From e4e35fcd07015c78bad7d3255c7d7d9a3b8bb9af Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Sat, 3 Feb 2024 14:32:53 +0100 Subject: [PATCH] Bug fixed, in case that the ping test was disabled, the ESP would reset every 120s by default. Version String added. Logger update interval (seconds) added. --- firmware/config.h | 3 +++ firmware/firmware.ino | 35 +++++++++++++++++------------ firmware/webUpdater.ino | 49 +++++++++++++++++++++++------------------ 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/firmware/config.h b/firmware/config.h index cd73300..f20adab 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -3,6 +3,8 @@ // config general setting and behavior of the weatherstation +#define VERSION_STRING "1.1.1" + #define WIFI_AUTOCONNECT_TIMEOUT_S 60 #define WIFI_CONFIG_PORTAL_TIMEOUT_S 120 #define UPDATE_SENSOR_INTERVAL_S 300 @@ -16,6 +18,7 @@ #define WATCHDOG_TIMEOUT_MS WDTO_8S // Look at Esp.h for further possible time declarations #define WIFI_CHECK_INTERVAL_MS 120000 #define INFLUXDB_TIMEOUT_MS 1000 +#define WEB_LOGGER_UPDATE_S 5 #define ENERGY_SAVING_ITERATIONS 30 diff --git a/firmware/firmware.ino b/firmware/firmware.ino index c203b83..5608ee5 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -13,11 +13,11 @@ #include "config_user.h" #ifdef ENABLE_PING_HOST_TEST -#include +#include // https://github.com/dancol90/ESP8266Ping #endif #ifndef DISABLE_WIFIMANAGER -#include // WiFiManager from bib manager +#include #endif #ifdef HTTP_CALL_ON_WINDSPEED_EXCEED @@ -286,7 +286,12 @@ void wifiConnectionCheck() { /*if (WiFi.status() == WL_CONNECTED) { // if we are connected return; - }*/ + } else { + debug("Connection problem (wlan problem), resetting ESP"); + delay(1000); + ESP.reset(); + } + */ #ifdef ENABLE_PING_HOST_TEST debug("Ping " + String(PING_HOST_IP)); @@ -295,17 +300,17 @@ void wifiConnectionCheck() { if (success) { debug("Ping success"); - return; + debug("Min Time: " + String(Ping.minTime()) + " ms"); + debug("Average Time: " + String(Ping.averageTime()) + " ms"); + debug("Max Time: " + String(Ping.maxTime()) + " ms"); + + } else { + debug("Connection problem (ping failed), resetting ESP"); + delay(1000); + ESP.reset(); } #endif // ENABLE_PING_HOST_TEST - debug("Connection problem, resetting ESP"); -#ifdef ENABLE_WATCHDOG - // loop endless, watchdog will reset the device - while (1 == 1) {} -#endif - ESP.reset(); - } #ifdef DISABLE_WIFIMANAGER @@ -559,8 +564,9 @@ void _fsm_loop() /* -------------------------------------------------------------------------------- */ case FSM_STATE_6: - //debug("log to serial if required"); + // #ifdef SERIAL_FEATURE + debug("log to serial"); logToSerial(currentSensorData); #endif fsm_state = FSM_STATE_7; @@ -568,7 +574,6 @@ void _fsm_loop() /* -------------------------------------------------------------------------------- */ case FSM_STATE_7: - //debug("send data to influxdb if required"); for (uint8_t i = 0; i < 5 and validData == false; i++) { // only check sensor data 0 to 4 -> SENSOR_TEMPERATURE, SENSOR_HUMIDITY, SENSOR_LIGHT, SENSOR_WINDSPEED, SENSOR_PRESSURE if (currentSensorData[i] != 0 and currentSensorData[i] != nanf("no value") and (not isnan(currentSensorData[i]))) { validData = true; @@ -577,6 +582,7 @@ void _fsm_loop() #ifdef INFLUXDB_FEATURE if (validData == true) { // send data only if valid data is available + debug("send data to influxdb"); pushToInfluxDB(DEVICE_NAME, currentSensorData); } #endif @@ -585,9 +591,10 @@ void _fsm_loop() /* -------------------------------------------------------------------------------- */ case FSM_STATE_8: - //debug("set sensor data in webupdater if required"); + #ifdef WEBUPDATER_FEATURE #ifdef SHOW_SENSOR_DATA_ON_WEBUPDATER_MAIN_PAGE + debug("set sensor data in webupdater"); setSensorData(currentSensorData); #endif #endif diff --git a/firmware/webUpdater.ino b/firmware/webUpdater.ino index 8ef896b..68b0a09 100644 --- a/firmware/webUpdater.ino +++ b/firmware/webUpdater.ino @@ -105,10 +105,11 @@ void setSensorData(float sensorValues[]) { void showHTMLMain(void) { - String message = "OKO Weatherstation - " + String(_webUpdater_dev) + "" - "" - "" - "
" + "" + "" + "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "
" + "
firmware update

" #ifdef USE_LOGGER "
" - "" - "" - "Rebooting...
" - ""; + String message = "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - reset WiFi manager" + "" + "" + "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "
" + "Rebooting...
" + ""; httpServer.send(200, "text/html", message); @@ -190,12 +192,13 @@ void resetESP() { void resetWifiManager() { - String message = "OKO Weatherstation - " + String(_webUpdater_dev) + " - reset WiFi manager" - "" - "" - "Reset WifiManager config.
" - "Rebooting...
" - ""; + String message = "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - reset WiFi manager" + "" + "" + "Reset WifiManager config.
" + "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "
" + "Rebooting...
" + ""; httpServer.send(200, "text/html", message); @@ -227,9 +230,10 @@ void measureWindspeed() { float tmp_windspeed = wind_speed(); digitalWrite(STATUS_LED_PIN, LOW); - String message = "OKO Weatherstation - " + String(_webUpdater_dev) + " - manual wind measurement" - "" - "Windsensor measurement result: " + String message = "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - manual wind measurement" + "" + "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "
" + "Windsensor measurement result: " + String(tmp_windspeed) + "
" ""; @@ -261,10 +265,11 @@ void logdata(String s) { } void showLog() { - String message = "OKO Weatherstation - " + String(_webUpdater_dev) + " - logfile" - "" - "" - "Logfile data:
"; + String message = "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - logfile" + "" + "" + "OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "
" + "Logfile data:
"; for (uint16_t lp = 0; lp < logger_pos; lp++) { message = message + logfile[lp] + "
";