Hardware Reference
In-Depth Information
Now, we need to use PHP to parse this variable that contains all the results from the query.
We simply use a while statement for that:
while($row = $results->fetchArray())
{
$dataset[] = array(strtotime($row['timestamp']) *
1000,$row['temperature']);
}
Note that in the process of parsing the results, we format the data in another variable, so
that the script we will use to plot the data can use it. We also convert the timestamp
column so that the plotting script can use it. In this example, we are just going to display
and later plot the temperature, which is why we only take these two variables out from the
database. You can, of course, do the same for the humidity.
Finally, we print out the formatted data in the JSON format:
echo json_encode($dataset);
Now, we can test this readout file. Simply go over to a terminal, go to the folder where the
file is located, and type:
php readout.php
This should plot all the recordings that have been made so far:
[[1400486855000,20],[1400486868000,20],[1400486879000,21],[1400486890000,21],[1400486901000,21],[1400486912000,21],[1400486922000,22],[1400486933000,23],[1400486944000,23]]
What are you are seeing in the terminal window is the raw data that was recorded for the
temperature. It consists of several small arrays of two elements, which are the timestamp
and recorded temperature. If you want to learn more about the JSON format that this PHP
script is returning, you can visit http://json.org/ .
If you can see this raw data being displayed, it means that the data coming from the Ardu-
ino board was correctly logged in your computer.
Search WWH ::




Custom Search