<?php
Template::stop();


$data = file_get_contents("php://input");
$data = json_decode($data);
//print_r($data);

if (!empty($data))
{
	global $_database;


	//-----------------------------------------------------------
	//$query = "UPDATE configuration SET relay_1 = $relay1, relay_2 = $relay2, commode = $commode WHERE sensor_id = sensorid";
	$query = 'INSERT INTO received_data (id, sensor_id, timestamp, tmp, hum, vltg, rssi) VALUES (NULL, "' . $data->sensor_id . '", CURRENT_TIMESTAMP, "' .$data->tmp. '", "' .$data->hum. '", "' .$data->vltg. '", "' .$data->rssi. '");';

	echo $query;
	$_database->setQuery($query);
	




}














/*


	// set table data - sensor configurations
	$query = '	INSERT INTO received_data (id, sensor_id, timestamp, tmp, hum, vltg, rssi) 
				VALUES 
			';
	$values = array();
	foreach ($data as $i => $sensor)
	{
		$values[] = '(NULL, "' . $sensor->sensor_id . '", CURRENT_TIMESTAMP, "' . $sensor->tmp . '", "' . $sensor->hum . '", "' . $sensor->vltg . '", "' . $sensor->rssi . '")';
	}
	$values_str = implode(',', $values);
	$query 		.= $values_str;

	$_database->setQuery($query);
}


print_r($data);
*/