Hardware Reference
In-Depth Information
Then, we will print out the data from the measurement on the page using the following
code:
client.print("Temperature: ");
client.print(temp);
client.print("<br />");
client.print("Humidity: ");
client.print(hum);
client.println("<br/>");
client.println("</html>");
The rest of the following code is there to detect whether we reached the end of the request
or not:
if (c == '\n') {
// Starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
Finally, we will give the browser a small delay to receive the answer, and we will close
the connection, as shown in the following code:
// Give the web browser time to receive the data
delay(1);
// Close the connection:
client.stop();
Serial.println("Client disconnected");
Note
All the code for this section can be found in the GitHub repository of this chapter at ht-
tps://github.com/openhomeautomation/arduino-networking/tree/master/chapter3 .
It's now time to test the code that we wrote in this section. Again, make sure that the Eth-
ernet cable is plugged to the Ethernet shield and to your router. Then, you can upload the
Search WWH ::




Custom Search