Hardware Reference
In-Depth Information
String temp = String((int) t);
String hum = String((int) h);
For debugging purposes, we also print these values on the Serial port. We'll check later
whether these values are correct when testing the sketch:
Serial.println("Temperature: " + temp);
Serial.println("Humidity: " + hum);
Now, we are actually going to send the data to the server. Don't worry about understand-
ing what the server-side code does for now, as we'll deal with that later. First, we have to
connect to the server running on your computer:
if (client.connect(server, 80)) {
if (client.connected()) {
Serial.println("connected");
If this is successful, we can make the request. As in Chapter 1 , Discover the Arduino Eth-
ernet Shield , we are going to use a standard GET request, and to pass the temperature and
humidity measurements as arguments. At this point, you will also need to enter the IP ad-
dress of your computer. This is all done using the following piece of code:
client.println("GET /datalogger/datalogger.php?temp=" +
temp + "&hum=" + hum + " HTTP/1.1");
client.println("Host: 192.168.1.100");
client.println("Connection: close");
client.println();
You can see that the code calls a filename datalogger.php , which we are going to ex-
amine in the next section.
Then, after the request is made, we can read the answer from the server:
while (client.connected()) {
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}
Search WWH ::




Custom Search