????JFIF??x?x????'
Server IP : 79.136.114.73 / Your IP : 13.59.50.189 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/appsrv.astacus.se/digitaltwin/sensors/ |
Upload File : |
<?php header ("Access-Control-Allow-Origin: *"); header("Content-type: application/json"); $method = $_SERVER ['REQUEST_METHOD']; if ($method == "OPTIONS") { die (); } session_start(); $link = mysql_connect ("localhost", "root", "root123"); mysql_select_db ("vpa"); $date_from = date('Y-m-d H:i:s', strtotime('-5 days')); $sql = "SELECT * FROM SENSORVALUES WHERE NOT SENSORNAME = '' AND time >= '".$date_from."' ORDER BY SENSORNAME, time DESC"; $result = mysql_query($sql); $JSON = "{"; $x=0; $sensorname_old = ""; //{"NAME1":[{"time":"2021-11-16 18:10:01","temp":22,"humidity":33.5,"dewpoint":5.2,"dewdiff":16.8,"pressure":1009 },{"time":"2021-11-16 18:00:01","temp":22,"humidity":33.7,"dewpoint":5.3,"dewdiff":16.7,"pressure":1009 }],"NAME2":[{"time":"2021-11-16 18:10:01","temp":22,"humidity":33.5,"dewpoint":5.2,"dewdiff":16.8,"pressure":1009 },{"time":"2021-11-16 18:00:01","temp":22,"humidity":33.7,"dewpoint":5.3,"dewdiff":16.7,"pressure":1009 }]} while ($row = mysql_fetch_assoc($result)){ $id = $row['SENSORVALUESID']; $sensorname = $row['SENSORNAME']; if( $row['time'] != ""){ if($sensorname_old != $sensorname){ if($x > 0){ $JSON = substr($JSON, 0, -1); $JSON .= '],'; } $JSON .= '"'.$sensorname.'":['; $sensorname_old = $sensorname; $x++; } $time = $row['time']; $temp = $row['temp']; $humidity = $row['humidity']; $dewpoint = $row['dewpoint']; $dewdiff = $row['dewdiff']; $pressure = $row['pressure']; if($temp == ""){$temp = 0;} if($humidity == ""){$humidity = 0;} if($dewpoint == ""){$dewpoint = 0;} if($dewdiff == ""){$dewdiff = 0;} if($pressure == ""){$pressure = 0;} $description = iconv("ISO-8859-1//IGNORE","UTF-8", $row['description']); $jsonobj = '{"time":"'.$time.'","description":"'.$description.'","temp":'.$temp.',"humidity":'.$humidity.',"dewpoint":'.$dewpoint.',"dewdiff":'.$dewdiff.',"pressure":'.$pressure.'},'; $JSON .= $jsonobj ; } } $JSON = substr($JSON, 0, -1); $JSON .= ']}'; //var_dump(json_decode($JSON,true)); echo(json_encode(json_decode($JSON,true))); ?>