Added signal quality and wifi connect count to default web page.

This commit is contained in:
Kai Lauterbach 2022-09-09 09:04:48 +02:00
parent 26300287f9
commit 26db5f74a9
2 changed files with 39 additions and 10 deletions

View file

@ -30,7 +30,9 @@
// constant variables // constant variables
const uint8_t VALUES = 8; // see constants.h file - count of number of SENSOR_ defines const uint8_t VALUES = 8; // see constants.h file - count of number of SENSOR_ defines
float currentSensorData[VALUES] = {nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value"), nanf("no value")}; float currentSensorData[VALUES] = { nanf("no value"), nanf("no value"), nanf("no value"),
nanf("no value"), nanf("no value"), nanf("no value"),
nanf("no value"), nanf("no value")};
float (*sensors[VALUES])() = {}; float (*sensors[VALUES])() = {};
uint16_t update_sensor_cnt = 0; uint16_t update_sensor_cnt = 0;
@ -41,6 +43,8 @@ boolean validData = false;
#ifdef USE_WIFIMANAGER #ifdef USE_WIFIMANAGER
WiFiManager wifiManager; WiFiManager wifiManager;
#else
unsigned int wifi_connect_cnt = 0;
#endif #endif
//*************************************************************************// //*************************************************************************//
@ -139,7 +143,8 @@ void setup()
debug("deep sleep"); debug("deep sleep");
// the ESP.deepSleep requires microseconds as input, after the sleep the system will run into the setup routine // the ESP.deepSleep requires microseconds as input, after the
// sleep the system will run into the setup routine
ESP.deepSleep(POWERSAVING_SLEEP_S * 1000000, WAKE_RF_DEFAULT); ESP.deepSleep(POWERSAVING_SLEEP_S * 1000000, WAKE_RF_DEFAULT);
delay(100); delay(100);
#endif #endif
@ -189,6 +194,7 @@ void wifiConnectionCheck()
Serial.println("WLAN connection already OK"); Serial.println("WLAN connection already OK");
return; return;
} }
WiFi.disconnect();
if (!WiFi.config(local_IP, gateway, subnet)) if (!WiFi.config(local_IP, gateway, subnet))
{ {
@ -205,9 +211,13 @@ void wifiConnectionCheck()
{ {
delay(100); delay(100);
} }
WiFi.setAutoReconnect(true);
WiFi.persistent(true);
Serial.println("WLAN connection OK"); Serial.println("WLAN connection OK");
wifi_connect_cnt += 1;
#endif #endif
} }
@ -372,7 +382,11 @@ void _loop()
#endif #endif
#ifdef WEBUPDATER_FEATURE #ifdef WEBUPDATER_FEATURE
#ifdef USE_WIFIMANAGER
setSensorData(currentSensorData); setSensorData(currentSensorData);
#else
setSensorData(currentSensorData, wifi_connect_cnt);
#endif
#endif #endif
} }

View file

@ -17,6 +17,8 @@
#ifdef USE_WIFIMANAGER #ifdef USE_WIFIMANAGER
#include <WiFiManager.h> // WiFiManager from bib manager #include <WiFiManager.h> // WiFiManager from bib manager
#else
unsigned int _wifi_connect_cnt = 0;
#endif #endif
ESP8266WebServer httpServer(WEB_UPDATER_HTTP_PORT); ESP8266WebServer httpServer(WEB_UPDATER_HTTP_PORT);
@ -74,7 +76,11 @@ void doWebUpdater(void)
httpServer.handleClient(); httpServer.handleClient();
} }
#ifdef USE_WIFIMANAGER
void setSensorData(float sensorValues[]) void setSensorData(float sensorValues[])
#else
void setSensorData(float sensorValues[], unsigned int wifi_conn_cnt)
#endif
{ {
for (uint8_t i = 0; i < 5 and wuValidData == false; i++) for (uint8_t i = 0; i < 5 and wuValidData == false; i++)
@ -89,6 +95,11 @@ void setSensorData(float sensorValues[])
_webUpdater_sensValues[i] = sensorValues[i]; _webUpdater_sensValues[i] = sensorValues[i];
} }
#ifndef USE_WIFIMANAGER
_wifi_connect_cnt = wifi_conn_cnt;
#endif
} }
void showHTMLMain(void) void showHTMLMain(void)
@ -101,12 +112,16 @@ void showHTMLMain(void)
"<table>" "<table>"
TR_TD_START_STR + "temperature" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_TEMPERATURE]) + TR_TD_END_STR TR_TD_START_STR + "temperature" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_TEMPERATURE]) + TR_TD_END_STR
TR_TD_START_STR + "humidity" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_HUMIDITY]) + TR_TD_END_STR TR_TD_START_STR + "humidity" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_HUMIDITY]) + TR_TD_END_STR
TR_TD_START_STR + "<tr><td>light" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_LIGHT]) + TR_TD_END_STR TR_TD_START_STR + "light" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_LIGHT]) + TR_TD_END_STR
TR_TD_START_STR + "<tr><td>windspeed" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_WINDSPEED]) + TR_TD_END_STR TR_TD_START_STR + "windspeed" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_WINDSPEED]) + TR_TD_END_STR
TR_TD_START_STR + "<tr><td>pressure" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_PRESSURE]) + TR_TD_END_STR TR_TD_START_STR + "pressure" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_PRESSURE]) + TR_TD_END_STR
TR_TD_START_STR + "<tr><td>batvoltage" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_BAT_VOLTAGE]) + TR_TD_END_STR TR_TD_START_STR + "batvoltage" + TD_TD_MID_STR + String(_webUpdater_sensValues[SENSOR_BAT_VOLTAGE]) + TR_TD_END_STR
TR_TD_START_STR + "<tr><td>millis" + TD_TD_MID_STR + String(millis()) + TR_TD_END_STR TR_TD_START_STR + "millis" + TD_TD_MID_STR + String(millis()) + TR_TD_END_STR
TR_TD_START_STR + "<tr><td>valid" + TD_TD_MID_STR + String(wuValidData) + TR_TD_END_STR TR_TD_START_STR + "valid" + TD_TD_MID_STR + String(wuValidData) + TR_TD_END_STR
TR_TD_START_STR + "wifi rssi" + TD_TD_MID_STR + WiFi.RSSI() + TR_TD_END_STR
#ifndef USE_WIFIMANAGER
TR_TD_START_STR + "wifi conn cnt" + TD_TD_MID_STR + _wifi_connect_cnt + TR_TD_END_STR
#endif
"</table>" "</table>"
"</body></html>"; "</body></html>";