Ok - so the sensor is seding through a mikrotik router which is in my chirpstack. The communication there works fine as seen in the screen shot below. Every 15 minutes a packet is received. Chirpsatack only shows the last 10 ppackets but it shows the problem. The packets for 6:33 and 6:48 are not received by the php page. Also below is the text saved by the php file. And finally here is my php
<?php
date_default_timezone_set("America/Los_Angeles");
$file = "./heltecdata.txt";
file_put_contents($file,"\n---- data rec'd ", FILE_APPEND |LOCK_EX);
file_put_contents($file,date("Y-m-d H:i:s"), FILE_APPEND |LOCK_EX);
file_put_contents($file,"\n", FILE_APPEND |LOCK_EX);
$json = file_get_contents('php://input');
$data = json_decode($json, true);
if (empty($data)) {file_put_contents($file, "File error decoding json", FILE_APPEND | LOCK_EX); exit();}
//else {
// foreach($data as $key => $val) {
// file_put_contents($file, "\nKEY IS: ".$key." val is: ".$val, FILE_APPEND | LOCK_EX);
// foreach($val as $_key => $_val) {
// file_put_contents($file, "\n Key IS: ".$_key." val is: ".$_val, FILE_APPEND | LOCK_EX);
// }
// }
//}
file_put_contents("./heltecdataraw.txt","-------------------------------\n--JSON\n", FILE_APPEND |LOCK_EX);
file_put_contents("./heltecdataraw.txt",$json, FILE_APPEND |LOCK_EX);
file_put_contents("./heltecdataraw.txt","\n", FILE_APPEND | LOCK_EX);
file_put_contents("./heltecdataraw.txt","--DATA\n", FILE_APPEND | LOCK_EX);
file_put_contents("./heltecdataraw.txt",$data, FILE_APPEND |LOCK_EX);
file_put_contents("./heltecdataraw.txt","\n", FILE_APPEND | LOCK_EX);
//file_put_contents("./heltecdataraw.txt","--SDATA\n", FILE_APPEND | LOCK_EX);
//file_put_contents("./heltecdataraw.txt",$sdata, FILE_APPEND |LOCK_EX);
$sensdata = $data['data'];
$sensdatab64 = base64_decode($sensdata);
$sensdatahex = bin2hex($sensdatab64);
//file_put_contents($file, "\nsensdata is: ".$sensdata." sensdatahex is: ".$sensdatahex." - ".$sensdatab64."\n+++++++++++++\n", FILE_APPEND | LOCK_EX);
$ztime = strtotime($data['time']);
$ltime = date("Y-m-d H:i:s", $ztime);
$devname = $data['deviceInfo']['deviceName'];
if ($devname == "Makerfab Soil Sensor") {
$soil = hexdec(substr($sensdatahex,4,4));
$abat = hexdec(substr($sensdatahex,8,2));
$hum = hexdec(substr($sensdatahex,10,4));
$senstemp = hexdec(substr($sensdatahex,14,4));
}
elseif ($devname == "GM Thermocouple") {
$t1f = hexdec(substr($sensdatahex,0,2));
$t2f = hexdec(substr($sensdatahex,2,2));
$t3f = hexdec(substr($sensdatahex,4,2));
$t4f = hexdec(substr($sensdatahex,6,2));
$t5f = hexdec(substr($sensdatahex,8,2));
$file = "./tcdata.csv";
$data_str = $ltime.",Device=".$devname.", Hexstr".$sensdatahex.",".$t1f.",".$t2f.",".$t3f.",".$t4f.",".$t5f."\n";
}
else {
$abat = hexdec(substr($sensdatahex,0,2));
$htemp = hexdec(substr($sensdatahex,2,2));
$soil = hexdec(substr($sensdatahex,4,2));
$senstemp = hexdec(substr($sensdatahex,6,2));
$hum = hexdec(substr($sensdatahex,8,2));
}
$ztime = strtotime($data['time']);
$ltime = date("Y-m-d H:i:s", $ztime);
file_put_contents($file, $data_str, FILE_APPEND | LOCK_EX);
/*file_put_contents($file, ", Device= ".$devname, FILE_APPEND | LOCK_EX);
file_put_contents($file, ", HexStr= ".$sensdatahex, FILE_APPEND | LOCK_EX);
file_put_contents($file, ", T1 = ".$t1f, FILE_APPEND | LOCK_EX);
file_put_contents($file, ", T2 = ".$t2f, FILE_APPEND | LOCK_EX);
file_put_contents($file, ", T3 = ".$t3f, FILE_APPEND | LOCK_EX);
file_put_contents($file, ", T4 = ".$t4f, FILE_APPEND | LOCK_EX);
file_put_contents($file, ", T5 = ".$t5f, FILE_APPEND | LOCK_EX);
file_put_contents($file, "\n", FILE_APPEND | LOCK_EX);
*/
?>
Chirpstack events
PHP output file
