<?php

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/EmptyPHP.php to edit this template
 */

require_once './Connection_getlark.php';

//if (!isset($_POST) == "") {

$input = file_get_contents('php://input');
$data = json_decode($input, true);
echo 'Data Recieve';
print_r($data);

// Print out the structure for testing
//var_dump($data);

//echo $sensor_data->type;
//}



$user_id = $data['user_id'];
$flow_meter_id = $data['flow_meter_id'];
$water_level = $data['water_level'];
$water_flow = $data['water_flow'];
$accumulative_water = $data['accumulative_water'];
$cumulative_traffic = $data['cumulative_traffic'];
$analog_output = $data['analog_output'];
$temperature = $data['temperature'];
$created_date = $data['CurrentDatetime'];

if($user_id!=""){

$query1 = " insert into tbl_flow_meter_data (user_id,flow_meter_id,water_level,water_flow,accumulative_water,cumulative_traffic,analog_output,temperature,created_date)"
        . " values ('$user_id','$flow_meter_id','$water_level','$water_flow','$accumulative_water','$cumulative_traffic','$analog_output','$temperature','$created_date') ";

try {
    if ($con) {

        if (mysqli_query($con, $query1)) {
            echo 'Data Store';
        } else {
            echo "Error:01";
        }
    } else {
        echo "Error:01";
    }
} catch (Exception $ex) {
    echo "Error:01";
}
}else{
    echo "Error:Blank";
}
?>