Log incoming data in a database
In this section, we are going to use PHP to build the server-side part of the project. If you are a complete novice in PHP, I recommend the following resource to learn the basics of the language:
http://php.net/manual/en/tutorial.php
First, we are going to see the content of the datalogger.php
file. This file will handle the requests coming from the Arduino board, log the data in a database, and answer with a simple message. Note that this file has to be in a folder named datalogger
on your web server. We will see the important parts of the code. To get the complete code for this section, please refer to the GitHub repository of the chapter. Note that all the PHP code should be between the <php … ?>
tags.
The file starts by receiving the data from the GET
request sent by the Arduino Ethernet shield:
$temperature = intval($_GET["temp"]); $humidity = intval($_GET["hum"]);
We also instantiate the connection with the SQLite database...