Logging feature added.

This commit is contained in:
Kai Lauterbach 2022-09-12 19:31:16 +02:00
parent c8626bb5cd
commit 0a605c7300
3 changed files with 62 additions and 9 deletions

View File

@ -13,7 +13,7 @@
#define RESET_ESP_TIME_INTERVAL_MS (60*60*12*1000) // reset every 12 hours
#define WIND_SENSOR_MEAS_TIME_S 15
#define WATCHDOG_TIMEOUT_MS 30000
#define WIFI_CHECK_INTERVAL_MS 60000
#define WIFI_CHECK_INTERVAL_MS 60000
#define ENERGY_SAVING_ITERATIONS 30
#define WIFI_MINIMUM_SIGNAL_QUALITY 10 // percent
#define BAT_LOW_VOLTAGE 3.6

View File

@ -55,6 +55,10 @@ void debug(String x)
#ifdef DEBUG
Serial.println(x);
#endif
#ifdef USE_LOGGER
logdata(String(millis()) + ":" + x);
#endif
}
//*************************************************************************//
@ -351,6 +355,7 @@ void _loop()
debug("read of wind sensor because of high battery enabled");
}
#endif
sensor_cnt = 0;
fsm_state = FSM_STATE_US;
break;
@ -358,7 +363,7 @@ void _loop()
debug("read sensor data check");
if (UPDATE_SENSOR_INTERVAL_S * 1000 / DELAY_LOOP_MS <= update_sensor_cnt)
{
debug("read sensor data" + String(sensor_cnt));
debug("read sensor data " + String(sensor_cnt));
if (sensors[sensor_cnt]) {
currentSensorData[sensor_cnt] = sensors[sensor_cnt]();
} else {
@ -368,10 +373,11 @@ void _loop()
if (sensor_cnt < VALUES)
{
sensor_cnt++;
fsm_state = FSM_STATE_US; // jump to same state again, more sensors to read
} else {
update_sensor_cnt = 0;
sensor_cnt = 0;
fsm_state = FSM_STATE_SC;
fsm_state = FSM_STATE_SC; // next state
}
} else {
debug("skip read sensor data");
@ -388,7 +394,7 @@ void _loop()
break;
case FSM_STATE_ID:
debug("Send data to influxdb");
debug("send data to influxdb if required");
#ifdef INFLUXDB_FEATURE
for (uint8_t i = 0; i < 5 and validData == false; i++)
{
@ -408,7 +414,7 @@ void _loop()
break;
case FSM_STATE_SD:
debug("set sensor data in webupdater");
debug("set sensor data in webupdater if required");
#ifdef WEBUPDATER_FEATURE
setSensorData(currentSensorData);
#endif
@ -423,7 +429,11 @@ void _loop()
//delay(100); // TODO warum hier ein delay?
debug("FSM state = " + String(fsm_state));
//debug("FSM state = " + String(fsm_state));
if (fsm_state == FSM_STATE_WU)
{
debug("----------");
}
}
void logToSerial(float sensorValues[])

View File

@ -55,7 +55,9 @@ void setupWebUpdater(String device, String ip)
#ifdef DEBUG_WINDSPEED_MEASUREMENT
httpServer.on("/measWind", measureWindspeed);
#endif
#ifdef USE_LOGGER
httpServer.on("/showlog", showLog);
#endif
httpServer.begin();
debug("HTTPUpdateServer ready!");
@ -139,7 +141,7 @@ void hb_webstat_send(void)
void resetWifiManager()
{
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + "</title>"
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>"
@ -169,7 +171,7 @@ void measureWindspeed()
float tmp_windspeed = wind_speed();
digitalWrite(STATUS_LED_PIN, LOW);
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + "</title>"
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - manual wind measurement</title>"
"</head><body>"
"Windsensor measurement result: " + String(tmp_windspeed) + "<br>"
"</body></html>";
@ -179,3 +181,44 @@ void measureWindspeed()
}
#endif
#endif
#ifdef USE_LOGGER
#define LOGFILE_SIZE 10
String logfile[LOGFILE_SIZE];
uint16_t logger_pos = 0;
void logdata(String s)
{
logfile[logger_pos] = s;
logger_pos++;
if (logger_pos > LOGFILE_SIZE -1)
{
for (uint16_t i = 1; i < LOGFILE_SIZE; i++)
{
logfile[i-1] = logfile[i]; // overwrite previous element with current element
}
logger_pos--; // reduce the position in the log
}
}
void showLog()
{
String message = "<html><head><title>OKO Weatherstation - " + String(_webUpdater_dev) + " - logfile</title>"
"</head><body>"
"Logfile data: ";
for (uint16_t lp = 0; lp < logger_pos; lp++)
{
message = message + logfile[lp] + "<br>";
}
message = message + "</body></html>";
httpServer.send(200, "text/html", message);
}
#endif