From 1c13707b39b3dba7fba7928832fe94b639ff369f Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Thu, 10 May 2018 17:55:00 +0200 Subject: [PATCH] Improvement to the ESP8266 Arduino code --- arduino-sensor/arduino-sensor.ino | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arduino-sensor/arduino-sensor.ino b/arduino-sensor/arduino-sensor.ino index af28baf..fb0430c 100644 --- a/arduino-sensor/arduino-sensor.ino +++ b/arduino-sensor/arduino-sensor.ino @@ -51,8 +51,8 @@ void setup() { if (c > 100) { Serial.println(); - Serial.println("Unable to connect. Sleeping for 30 seconds before trying again."); - int sleepTime = 30 * 1e6; + Serial.println("Unable to connect. Sleeping for 60 seconds before trying again."); + int sleepTime = 60 * 1e6; ESP.deepSleep(sleepTime); } } @@ -70,11 +70,11 @@ void loop() { t = bmp.readTemperature(); } - Serial.println("Got t=" + String(t) + " and h=" + String(h) + "..."); - + Serial.println("Got t=" + String(t) + " and h=" + String(h) + "."); String content = "{\n"; - //content += "\"id\": \"" + String(getNodeId()) + "\",\n"; + content += "\"id\": \"" + WiFi.macAddress() + "\",\n"; + content += "\"name\": \"" + String(getNodeId()) + "\",\n"; content += "\"temp\": " + String(t) + ",\n"; content += "\"pressure\": " + String(h) + "\n"; content += "}\n"; @@ -84,7 +84,7 @@ void loop() { String response = ""; int statusCode = 0; - while (statusCode < 100) { + while (statusCode < 100 || statusCode >= 500) { RestClient client = RestClient(host, httpsPort, 1); const char * contentArr = content.c_str(); statusCode = client.post(path, contentArr, &response); @@ -92,8 +92,8 @@ void loop() { Serial.println("Got response code: " + String(statusCode)); Serial.println("Got response: " + response); - if (statusCode < 100) { - delay(2500); + if (statusCode < 100 || statusCode >= 500) { + delay(5000); } } @@ -107,7 +107,7 @@ void loop() { Serial.print("Going to sleep for "); Serial.print(sleepTime); - Serial.print(" nanoseconds"); + Serial.println(" nanoseconds"); ESP.deepSleep(sleepTime); /*