Improved sensor data read code.

This commit is contained in:
Kai Lauterbach 2022-09-13 10:48:58 +02:00
parent 0482db2f21
commit d2b9851bc1
3 changed files with 39 additions and 7 deletions

View file

@ -5,9 +5,9 @@
#define WIFI_AUTOCONNECT_TIMEOUT_S 120 #define WIFI_AUTOCONNECT_TIMEOUT_S 120
#define WIFI_CONFIG_PORTAL_TIMEOUT_S 120 #define WIFI_CONFIG_PORTAL_TIMEOUT_S 120
#define UPDATE_SENSOR_INTERVAL_S 300 #define UPDATE_SENSOR_INTERVAL_S 180
#define UPDATE_WEBSERVER_INTVERVAL_S 1 // Do not change, bigger values will prevent using webupdater webinterface #define UPDATE_WEBSERVER_INTVERVAL_S 1 // Do not change, bigger values will prevent using webupdater webinterface
#define DELAY_LOOP_MS 50 #define DELAY_LOOP_MS 100
#define POWERSAVING_SLEEP_S 600 #define POWERSAVING_SLEEP_S 600
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover #define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
#define RESET_ESP_TIME_INTERVAL_MS (60*60*12*1000) // reset every 12 hours #define RESET_ESP_TIME_INTERVAL_MS (60*60*12*1000) // reset every 12 hours

View file

@ -32,6 +32,15 @@ float currentSensorData[VALUES] = { nanf("no value"), nanf("no value"), nanf("no
nanf("no value"), nanf("no value") }; nanf("no value"), nanf("no value") };
float (*sensors[VALUES])() = {}; float (*sensors[VALUES])() = {};
uint8_t sensor_value[] = { SENSOR_TEMPERATURE,
SENSOR_HUMIDITY,
SENSOR_LIGHT,
SENSOR_WINDSPEED,
SENSOR_PRESSURE,
SENSOR_BAT_VOLTAGE,
SENSOR_ESAVEMODE,
SENSOR_BATCHARGESTATE };
uint32_t update_sensor_cnt = 0; uint32_t update_sensor_cnt = 0;
uint32_t update_webserver_cnt = 0; uint32_t update_webserver_cnt = 0;
uint32_t update_windspeed_exceed_cnt = 0; uint32_t update_windspeed_exceed_cnt = 0;
@ -341,13 +350,13 @@ void _loop()
debug("read sensor data " + String(sensor_cnt)); debug("read sensor data " + String(sensor_cnt));
if (sensors[sensor_cnt]) if (sensors[sensor_cnt])
{ {
debug("sensors[" + String(sensor_cnt) + "]=" + String((int)sensors[sensor_cnt])); debug("sensors[sensor_value[" + String(sensor_cnt) + " ]]=" + String((int)sensors[sensor_value[sensor_cnt]]) + ":" + String(sensor_value[sensor_cnt]));
//currentSensorData[sensor_cnt] = sensors[sensor_cnt](); currentSensorData[sensor_cnt] = sensors[sensor_value[sensor_cnt]]();
currentSensorData[sensor_cnt] = sensor_cnt; //currentSensorData[sensor_cnt] = sensor_cnt;
} else { } else {
debug("sensors[" + String(sensor_cnt) + "]=nan"); debug("sensors[sensor_value[" + String(sensor_cnt) + "]]=nan");
currentSensorData[sensor_cnt] = nan("no value"); currentSensorData[sensor_cnt] = nan("no value");
} }
@ -450,6 +459,11 @@ void readWindSpeedExceed()
debug("Called windspeed exceed callout"); debug("Called windspeed exceed callout");
digitalWrite(STATUS_LED_PIN, LOW); digitalWrite(STATUS_LED_PIN, LOW);
} }
#ifdef WEBUPDATER_FEATURE
setSensorData(currentSensorData);
#endif
} else { } else {
currentSensorData[SENSOR_WINDSPEED] = nan("no value"); currentSensorData[SENSOR_WINDSPEED] = nan("no value");
} }

View file

@ -16,6 +16,8 @@
#include "config.h" #include "config.h"
#include "config_user.h" #include "config_user.h"
//*************************************************************************//
ESP8266WebServer httpServer(WEB_UPDATER_HTTP_PORT); ESP8266WebServer httpServer(WEB_UPDATER_HTTP_PORT);
ESP8266HTTPUpdateServer httpUpdater; ESP8266HTTPUpdateServer httpUpdater;
@ -39,6 +41,8 @@ const String hb_ws_msg_end = "}";
boolean wuValidData = false; boolean wuValidData = false;
//*************************************************************************//
void setupWebUpdater(String device, String ip) void setupWebUpdater(String device, String ip)
{ {
debug("Starting WebUpdater... " + ip); debug("Starting WebUpdater... " + ip);
@ -63,6 +67,8 @@ void setupWebUpdater(String device, String ip)
debug("HTTPUpdateServer ready!"); debug("HTTPUpdateServer ready!");
} }
//*************************************************************************//
void doWebUpdater(void) void doWebUpdater(void)
{ {
digitalWrite(D0, HIGH); digitalWrite(D0, HIGH);
@ -85,6 +91,8 @@ void setSensorData(float sensorValues[])
} }
} }
//*************************************************************************//
void showHTMLMain(void) void showHTMLMain(void)
{ {
@ -118,6 +126,8 @@ TR_TD_START_STR + "wifi rssi" + TD_TD_MID_STR + WiFi.RSSI()
httpServer.send(200, "text/html", message); httpServer.send(200, "text/html", message);
} }
//*************************************************************************//
#ifdef HOMEBRIDGE_WEBSTAT #ifdef HOMEBRIDGE_WEBSTAT
void hb_webstat_send(void) void hb_webstat_send(void)
{ {
@ -148,6 +158,8 @@ void hb_webstat_send(void)
} }
#endif #endif
//*************************************************************************//
void resetWifiManager() void resetWifiManager()
{ {
@ -170,6 +182,8 @@ void resetWifiManager()
ESP.restart(); ESP.restart();
} }
//*************************************************************************//
#ifdef DEBUG_WINDSPEED_MEASUREMENT #ifdef DEBUG_WINDSPEED_MEASUREMENT
#ifdef SENSOR_WIND #ifdef SENSOR_WIND
void measureWindspeed() void measureWindspeed()
@ -192,9 +206,11 @@ void measureWindspeed()
#endif #endif
#endif #endif
//*************************************************************************//
#ifdef USE_LOGGER #ifdef USE_LOGGER
#define LOGFILE_SIZE 15 #define LOGFILE_SIZE 20
String logfile[LOGFILE_SIZE]; String logfile[LOGFILE_SIZE];
@ -233,3 +249,5 @@ void showLog()
} }
#endif #endif
//*************************************************************************//