CHAPTER 8 ■ IOT PATTERNS: WEB APPS
void transmitSensorData()
{
// Read all incoming data (if any)
while (client.available())
{
char c = client.read();
Serial.write(c);
}
if (millis() - lastConnectionTime > postingInterval)
{
client.stop();
Serial.println("[INFO] Connecting to Server");
String requestData = "temperature=" + String(temperatureF);
// Prepare data or parameters that need to be posted to server
if (client.connect(server, port))
{
Serial.println("[INFO] Server Connected - HTTP GET Started");
// Make a HTTP request:
client.println("GET /tempmonitor/add.php?" + requestData +
" HTTP/1.1");
client.println("Host: " + String(server));
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
Serial.println("[INFO] HTTP GET Completed");
}
else
{
// Connection to server:port failed
Serial.println("[ERROR] Connection Failed");
}
}
Serial.println("-----------------------------------------------");
}