For my Project I'm using a raspberry pi which, after processing values from the sensor with the function conv_aqi(), is supposed to send them on a database hosted on 000webhost so that everyone can see them. The code does not produce errors, but values are missing on the db. I'm trying to pass those values are json. This is the python script:
import requests
def sendDatatoServer():
url = 'https://*******.000webhostapp.com/api/insert.php'
data = {
'aqi_2_5' : 'conv_aqi(pmt_2_5)',
'aqi_10' : 'conv_aqi(pmt_10)',
}
print(data)
res = requests.post(url, data)
print(res.text)
sendDatatoServer()
where the insert.php on the 000webhost is the following:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
//Creating Array for JSON response
$response = array();
// Check if we got the field from the user
if (isset($_GET['AQI_2_5']) && isset($_GET['AQI_10'])) {
$AQI_2_5 = $_GET['AQI_2_5'];
$AQI_10 = $_GET['AQI_10'];
// Include data base connect class
$filepath = realpath (dirname(__FILE__));
require_once($filepath."/db_connect.php");
// Connecting to database
$db = new DB_CONNECT();
// Fire SQL query to insert data in sensorData
$result = mysql_query("INSERT INTO sensorData(AQI_2_5,AQI_10) VALUES('$AQI_2_5','$AQI_10')");
// Check for succesfull execution of query
if ($result) {
// successfully inserted
$response["success"] = 1;
$response["message"] = "Data from sensor successfully created.";
// Show JSON response
echo json_encode($response);
} else {
// Failed to insert data in database
$response["success"] = 0;
$response["message"] = "Something went wrong";
// Show JSON response
echo json_encode($response);
}
} else {
// If required parameter is missing
$response["success"] = 0;
$response["message"] = "Parameter(s) are missing. Please check the request";
// Show JSON response
echo json_encode($response);
}
?>
And what I get is "Parameters are missing. Please check the request". Can I please have a hand on understanding where I'm mistaken ? Thanks