Datalogger with MySQL
In the following section, we will build a Datalogger that will record the data temperature and humidity in the server so that we can get data whenever we want and display it in a web page.
Programming the script software
In the following code, we have a script that will communicate with the Arduino board, and it is installed in the server.
You can now either copy the code inside a file called datalogger1.php, or just get the complete code from the folder for this project:
<?php
if (isset($_GET["temp"]) && isset($_GET["hum"])) {
$temperature = intval($_GET["temp"]);
$humidity = intval($_GET["hum"]);
$con=mysql_connect("localhost","root","ruben","arduinobd");
mysql_select_db('arduinobd',$con);
if(mysql_query("INSERT INTO measurements (temperature, humidity) VALUES ('$temperature', '$humidity');")){
echo "Data were saved";
}
else {
echo "Fail the recorded data";
...