Building Arduino Projects for the Internet of Things

(Steven Felgate) #1
CHAPTER 8 ■ IOT PATTERNS: WEB APPS

Listing 8-3. Code to Receive and Store Data in add.php


<?php
include('util-dbconn.php');


$temperature = $_GET['temperature'];
echo "[DEBUG] Temperature Sensor Data: ". $temperature. "\n";
$sql = "INSERT INTO TEMPERATURE_MONITORING_DATA(TEMPERATURE) VALUES
($temperature)";


if (!$result = $mysqli->query($sql))
{
echo "[Error] ". mysqli_error(). "\n";
exit();
}


$mysqli->close();


echo "[DEBUG] New Temperature Sensor Data Added Successfully\n";


?>


D a s h b o a r d


All the data that is being captured by the sensor and stored in database is not visible to
anyone. So next, you are going to build an analytics dashboard that will load the last 30
entries from the database and display them in a bar chart format. As shown in Figure  8-8 ,
create a new file called index.php in the tempmonitor folder.


Figure 8-8. The file for analytics dashboard is index.php

Free download pdf