| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 
 | <?php
/* *** receive data from telemesure.net service
*/
define("MODE", "DECODED"); //use GET, POST or EXTENDED
define("FILENAME", "lognivose/clientraw.txt"); //name of the file
if (MODE === "GET") {
	$id = $_GET["id"]; // transmitter ID
	$data = $_GET["data"]; // payload
	file_put_contents(FILENAME, "$id,$data\n", FILE_APPEND | LOCK_EX);
 
} else if (MODE === "POST") {
	$id = $_POST["id"]; // transmitter ID
	$data = $_POST["data"]; // payload
	file_put_contents(FILENAME, "$id,$data\n", FILE_APPEND | LOCK_EX);
 
} else if (MODE === "EXTENDED") {
	$id = $_POST["id"]; // transmitter ID
	$data = $_POST["data"]; // payload
	$node_ref = $_POST["node_ref"]; // id of the receiver
	$link_quality = $_POST["link_quality"]; // level of the link quality
	$rssi = $_POST["rssi"]; // intensity of signal
	$lat = $_POST["lat"]; // geo latitude
	$lng = $_POST["lng"]; // geo longitude
	file_put_contents(FILENAME, "$id,$data\n", FILE_APPEND | LOCK_EX);
	file_put_contents(FILENAME, ">>FROM:$node_ref LinkQuality:$link_quality Rssi:$rssi lat=$lat lng=$lng\n", FILE_APPEND | LOCK_EX);
 
} else if (MODE === "DECODED") {
	$receivedData = json_decode(file_get_contents('php://input'), true); //Decode received json data
	$id = $receivedData["id"]; // transmitter ID
	$raw_data = $receivedData["raw_data"]; // Encoded raw data
 
	//Unstack received data to exploit it
	$datas = $receivedData["datas"];
	$unstackedData = [];
	foreach ($datas as $data => $content) { // Iterate on each evenement
		$timestamp = $content["timestamp"]; // Get timestamp of event
		file_put_contents(FILENAME, "$timestamp\n", FILE_APPEND | LOCK_EX);
		$values = $content["values"];
		array_push($unstackedData, [$values]);
		foreach ($values as $key => $value)
			file_put_contents(FILENAME, "$value\n", FILE_APPEND | LOCK_EX);
	}
	file_put_contents(FILENAME, "", FILE_APPEND | LOCK_EX);
} | 
Partager