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.

This commit is contained in:
Kai Lauterbach 2024-02-03 14:32:53 +01:00
parent 12aec59c20
commit e4e35fcd07
3 changed files with 51 additions and 36 deletions

View file

@ -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

View file

@ -13,11 +13,11 @@
#include "config_user.h"
#ifdef ENABLE_PING_HOST_TEST
#include <ESP8266Ping.h>
#include <ESP8266Ping.h> // https://github.com/dancol90/ESP8266Ping
#endif
#ifndef DISABLE_WIFIMANAGER
#include <WiFiManager.h> // WiFiManager from bib manager
#include <WiFiManager.h>
#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

View file

@ -105,10 +105,11 @@ void setSensorData(float sensorValues[]) {
void showHTMLMain(void) {
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + "</title>"
"<meta http-equiv=\"refresh\" content=\"20\">"
"</head><body>"
"<br><a href=\"http://"
String message = "<html><head><title>OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "</title>"
"<meta http-equiv=\"refresh\" content=\"20\">"
"</head><body>"
"OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "<br>"
"<br><a href=\"http://"
+ _webUpdater_ip + ":8080/update\">firmware update</a><br><br>"
#ifdef USE_LOGGER
"<br><a href=\"http://"
@ -165,11 +166,12 @@ void hb_webstat_send(void) {
void resetESP() {
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - reset WiFi manager</title>"
"<meta http-equiv=\"refresh\" content=\"20\">"
"</head><body>"
"Rebooting...<br>"
"</body></html>";
String message = "<html><head><title>OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - reset WiFi manager</title>"
"<meta http-equiv=\"refresh\" content=\"20\">"
"</head><body>"
"OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "<br>"
"Rebooting...<br>"
"</body></html>";
httpServer.send(200, "text/html", message);
@ -190,12 +192,13 @@ void resetESP() {
void resetWifiManager() {
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - reset WiFi manager</title>"
"<meta http-equiv=\"refresh\" content=\"20\">"
"</head><body>"
"Reset WifiManager config.<br>"
"Rebooting...<br>"
"</body></html>";
String message = "<html><head><title>OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - reset WiFi manager</title>"
"<meta http-equiv=\"refresh\" content=\"20\">"
"</head><body>"
"Reset WifiManager config.<br>"
"OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "<br>"
"Rebooting...<br>"
"</body></html>";
httpServer.send(200, "text/html", message);
@ -227,9 +230,10 @@ void measureWindspeed() {
float tmp_windspeed = wind_speed();
digitalWrite(STATUS_LED_PIN, LOW);
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - manual wind measurement</title>"
"</head><body>"
"Windsensor measurement result: "
String message = "<html><head><title>OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - manual wind measurement</title>"
"</head><body>"
"OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "<br>"
"Windsensor measurement result: "
+ String(tmp_windspeed) + "<br>"
"</body></html>";
@ -261,10 +265,11 @@ void logdata(String s) {
}
void showLog() {
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - logfile</title>"
"<meta http-equiv=\"refresh\" content=\"5\">"
"</head><body>"
"Logfile data:<br>";
String message = "<html><head><title>OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + " - logfile</title>"
"<meta http-equiv=\"refresh\" content=\""+String(WEB_LOGGER_UPDATE_S)+"\">"
"</head><body>"
"OKO Weatherstation " + String(VERSION_STRING) + " - " + String(_webUpdater_dev) + "<br>"
"Logfile data:<br>";
for (uint16_t lp = 0; lp < logger_pos; lp++) {
message = message + logfile[lp] + "<br>";