Book Image

Arduino Networking

By : Marco Schwartz
Book Image

Arduino Networking

By: Marco Schwartz

Overview of this book

Table of Contents (13 chapters)

Plotting the data locally


To end the chapter, we are going to see how to plot data measured by the Arduino board. To do so, we will modify the Arduino sketch a little bit, and then use part of the code from the previous chapter to plot the data right in your web browser.

First, we are going to modify the Arduino sketch so that it returns data in a more useful format; in the present case, the JSON format. In place of the code responsible to print out the measurements, we are going to simply print the data in the JSON format. This is done using the following piece of code:

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println();
client.print("{\"temperature\": ");
client.print(temp);
client.print(", \"humidity\": ");
client.print(hum);
client.println("}");

We can now quickly test this project. Upload the code to the Arduino board again, open your web browser, and go to the same IP address you used before. You should...