CHAPTER 3 ■ COMMUNICATION PROTOCOLS
40
Listing 3-5. Code for Standard Arduino Functions—loop()
void loop()
{
if (client.available())
{
Serial.println("[INFO] HTTP Response");
}
// Read available incoming bytes from the server and print
while (client.available())
{
char c = client.read();
Serial.write(c);
}
// If the server:port has disconnected, then stop the client
if (!client.connected())
{
Serial.println();
Serial.println("[INFO] Disconnecting From Server");
client.stop();
}
}
Your Arduino code is complete.
Final Product
To test the application, verify and upload the code as discussed in Chapter 1 . Once the
code has been uploaded, open the Serial Monitor window. You will start seeing log
messages similar to ones shown in Figure  3-2 for HTTP GET and in Figure  3-3 for HTTP
POST .
Précédent

- 61/299

Suivant