false) { include 'sensorregional.php'; if (isset ($regional_user) && $regional_user <> 'user') { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $regional_url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ch, CURLOPT_POSTFIELDS, $json); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt( $ch, CURLOPT_HTTPHEADER,array( 'Content-Type: application/json', 'X-Sensor: '.$header_sensor, 'Content-Length: '.strlen($json), 'Connection: close')); $result = curl_exec($ch); curl_close ($ch);} } # #------------------- save last measurements-json $lastdata = $data_dir.'/last_luft_data.json'; file_put_contents($lastdata,$json); # #---------------------- do we create daily files if ($load_data_csv == false) {return;} # $results= json_decode($json,true); if ($results == false) { echo 'Results: '.var_dump ($results,true); return;} // invalid data, TODO add message # header_remove(); // ?? # $now = date('c'); $today = date('Ymd'); # #------ copy sensor data values to values array foreach ($results["sensordatavalues"] as $arr) { $key = $arr["value_type"]; $values[$key] = $arr["value"]; } # #---------------------- print transmitted values #echo "Sensor: ".$header_sensor.PHP_EOL; # #------- check if data dir exists, create if not if (!file_exists($data_dir)) { mkdir($data_dir, 0755, true);} # #------ create first line of CSV with fieldnames $names = 'time'; foreach ($luft_fields as $name) {$names .= ';'.$name;} $names .= "\n"; # #----------- create one line with field contents $contents = $now; foreach ($luft_fields as $name) { if (!isset($values[$name])) { $values[$name] = '';} $contents .= ';'.$values[$name];} $contents .= "\n"; # #------------------------- save this measurement $lastdata = $data_dir.'/last_luft_data.csv'; file_put_contents($lastdata,$names.$contents); # #---- save data values to CSV in one file per day $datafile = $data_dir.'/data-'.$header_sensor.'-'.$today.'.csv'; # #--- line with the fieldnames if file not exists if (file_exists($datafile)) { $names = '';} # #----------- save this measurement in daily file $outfile = fopen($datafile,"a"); fwrite($outfile, $names.$contents); fclose($outfile); if ($test_mode == true) {echo '
'.$contents.'
';} ?> ok