Building Arduino Projects for the Internet of Things

(Steven Felgate) #1

CHAPTER 8 ■ IOT PATTERNS: WEB APPS


F i g u r e 8-5 shows the structure of the TEMPERATURE_MONITORING_DATA table.

Figure 8-5. TEMPERATURE_MONITORING_DATA table structure


Code (PHP)


Now that the database table is ready, you need to build two services. The first service
will receive the Arduino sensor data and store it in the newly created database table. The
second service will show historical sensor data in a dashboard.
This project also uses PHP for building data storage and interface services.
Create a new folder called tempmonitor in the public/root folder of your PHP
server. All of the PHP source code for this project will go in this tempmonitor folder.
Start a text editor of your choice.


■ Note All the PHP code was developed using Brackets, which is an open source text


editor. See http://brackets.io/ for more information.


Database Connection xii


The PHP scripts for storing and displaying data will need to connect to the database. As
shown in Figure  8-6 , create a new file called util-dbconn.php in the tempmonitor folder.
This file will be used by both scripts instead of repeating the code.

Free download pdf