1

Code to Send data to webpage via I2C from Ardunio and PI

<?php
//https://python.faith/dax/api1.php?sensorlocation=location1&sensortype=DHT11&temp=57&humidity=20
//https://python.faith/dax/api1.php?Devices=PIPICOW&Sensor_name=DHT11

$sensorlocation=$_GET['sensorlocation'];
$sensortype=$_GET['sensortype'];
$temp=$_GET['temp'];
$humidity=$_GET['humidity'];
$Sensor2_name2=$_GET['sensor2_name2'];
$Sensor2_Humidity2=$_GET['sensor2_humidity2'];
$Sensor2_Temp2=$_GET['sensor2_temp2'];
$unixtime=$_GET['unixtime'];

echo "<br>";
echo $Device;
echo $Sensor_name1;
echo $Sensor_Humidity1;
echo "<br>";
//$datetime = time();


$servername = "localhost";
$database = "";
$username = "";
$password = "";
 
// Create connection
 
$con = mysqli_connect($servername, $username, $password, $database);

$sql = "INSERT INTO weather (sensorlocation, sensortype,  temp, humidity, unixtime) VALUES ('" . $sensorlocation . "', '" . " $sensortype " . "','" . $temp . "','" . $humidity . "' ,'" . $unixtime . "')";

//$sql = "INSERT INTO weather (sensorlocation, sensortype,  temp, humidity) VALUES ('" . $sensorlocation . "', '" . " $sensortype " . "','" . $temp . "','" . $humidity . "')";


//$sql = "INSERT INTO temp (sensorlocation, sensortype,  temp, humidity, time) VALUES ('" . $sensorlocation . "', '" . " $sensortype " . "','" . $temp . "','" . $humidity . "','" . $datetime . "')";


//$sql = "INSERT INTO temp (sensorlocation, sensortype,  temp, humidity, time) VALUES ('" . $Device . "', '" . " $Sensor_name1 " . "','" . $Sensor_Humidity1 . "','" . $Sensor_Temp1 . "','" . $datetime . "','" . $Sensor2_name2 . "','" . $Sensor2_Humidity2 . "','" . $Sensor2_Temp2 . "','" . $avgtemp. "','" . $avghum . "')";



//sensorlocation
//sensortype
//temp
//humidity
//time





echo "<br>";
echo $sql;
echo "<br>";
//echo $con;
echo "<br>";


if (mysqli_query($con, $sql)) {
      echo "New record created successfully";
} else {
      echo "Error: " . $sql . "<br>" . mysqli_error($con);
      echo "<br>";
      echo "error";
}



mysqli_close($con);
?>