<?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'];
$flow_velocity = $data['flow_velocity'];
$water_level = $data['water_level'];
$empty_height = $data['empty_height'];
$small_instantaneous_flow = $data['small_instantaneous_flow'];
$cumulative_traffic_higher = $data['cumulative_traffic_higher'];
$cumulative_traffic_middle = $data['cumulative_traffic_middle'];
$cumulative_traffic_lower = $data['cumulative_traffic_lower'];
$velocity_signal_intensity = $data['velocity_signal_intensity'];
$water_level_signal_strength = $data['water_level_signal_strength'];
$flow_direction = $data['flow_direction'];
$flow_noise_threshold = $data['flow_noise_threshold'];
$water_level_noise_threshold = $data['water_level_noise_threshold'];
$created_date = $data['CurrentDatetime'];

if($user_id!=""){

$query1 = " insert into tbl_radar_flow_meter_data (user_id,flow_meter_id,flow_velocity,water_level,empty_height,small_instantaneous_flow,cumulative_traffic_higher,cumulative_traffic_middle,cumulative_traffic_lower,velocity_signal_intensity,water_level_signal_strength,flow_direction,flow_noise_threshold,water_level_noise_threshold,created_date)"
        . " values ('$user_id','$flow_meter_id','$flow_velocity','$water_level','$empty_height','$small_instantaneous_flow','$cumulative_traffic_higher','$cumulative_traffic_middle','$cumulative_traffic_lower','$velocity_signal_intensity','$water_level_signal_strength','$flow_direction','$flow_noise_threshold','$water_level_noise_threshold','$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";
}
?>