From 78a628dc4f31c761f1d74a1336b2edc14be0930e Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 3 Jun 2021 17:08:53 +0700 Subject: [PATCH] sending sensor_id for future multiple sensors and some better error correction --- aqi_monitor/aqi_monitor.ino | 13 +++++++------ aqi_monitor/config.sample.h | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/aqi_monitor/aqi_monitor.ino b/aqi_monitor/aqi_monitor.ino index d8a4e8a..ac1dec5 100644 --- a/aqi_monitor/aqi_monitor.ino +++ b/aqi_monitor/aqi_monitor.ino @@ -55,8 +55,8 @@ void setup() { } // main loop speed - if (sds011.setDutyCycle(2)) { - Serial.println("SDS011 Duty Cycle set to 2min"); + if (sds011.setDutyCycle(3)) { + Serial.println("SDS011 Duty Cycle set to 3min"); } else { Serial.println("FAIL: Unable to set Duty Cycle"); } @@ -119,6 +119,7 @@ void loop() { doc["humidity"] = humidity; doc["pm25"] = pm25; doc["pm10"] = pm10; + doc["sensor_id"] = sensorId; // send data String response; @@ -138,7 +139,7 @@ void loop() { // retry on error int retry = 0; while ((!client.connect(host, 443)) && (retry < 5)) { - delay(1000); + delay(2000); Serial.print("."); retry++; } @@ -175,13 +176,13 @@ void loop() { WiFi.reconnect(); reconnects ++; // try reconnecting - while (WiFi.status() != WL_CONNECTED && reconnects < 10 ) { - delay(2000); + while (WiFi.status() != WL_CONNECTED && reconnects < 5 ) { + delay(10000); Serial.print("."); reconnects ++; } // restart if all failed - if (WiFi.status() == WL_CONNECTED) { + if (WiFi.status() != WL_CONNECTED) { ESP.restart(); } diff --git a/aqi_monitor/config.sample.h b/aqi_monitor/config.sample.h index 756bc3d..4e4cebb 100644 --- a/aqi_monitor/config.sample.h +++ b/aqi_monitor/config.sample.h @@ -5,3 +5,5 @@ const char* password = "my-wifi-password"; const char* authUsername = "username"; const char* authPassword = "password"; + +const int sensorId = 1;