feature/http_call_send_json #3
3 changed files with 62 additions and 9 deletions
|
@ -55,6 +55,10 @@ void debug(String x)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println(x);
|
Serial.println(x);
|
||||||
#endif
|
#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");
|
debug("read of wind sensor because of high battery enabled");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
sensor_cnt = 0;
|
||||||
fsm_state = FSM_STATE_US;
|
fsm_state = FSM_STATE_US;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -358,7 +363,7 @@ void _loop()
|
||||||
debug("read sensor data check");
|
debug("read sensor data check");
|
||||||
if (UPDATE_SENSOR_INTERVAL_S * 1000 / DELAY_LOOP_MS <= update_sensor_cnt)
|
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]) {
|
if (sensors[sensor_cnt]) {
|
||||||
currentSensorData[sensor_cnt] = sensors[sensor_cnt]();
|
currentSensorData[sensor_cnt] = sensors[sensor_cnt]();
|
||||||
} else {
|
} else {
|
||||||
|
@ -368,10 +373,11 @@ void _loop()
|
||||||
if (sensor_cnt < VALUES)
|
if (sensor_cnt < VALUES)
|
||||||
{
|
{
|
||||||
sensor_cnt++;
|
sensor_cnt++;
|
||||||
|
fsm_state = FSM_STATE_US; // jump to same state again, more sensors to read
|
||||||
} else {
|
} else {
|
||||||
update_sensor_cnt = 0;
|
update_sensor_cnt = 0;
|
||||||
sensor_cnt = 0;
|
sensor_cnt = 0;
|
||||||
fsm_state = FSM_STATE_SC;
|
fsm_state = FSM_STATE_SC; // next state
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug("skip read sensor data");
|
debug("skip read sensor data");
|
||||||
|
@ -388,7 +394,7 @@ void _loop()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_ID:
|
case FSM_STATE_ID:
|
||||||
debug("Send data to influxdb");
|
debug("send data to influxdb if required");
|
||||||
#ifdef INFLUXDB_FEATURE
|
#ifdef INFLUXDB_FEATURE
|
||||||
for (uint8_t i = 0; i < 5 and validData == false; i++)
|
for (uint8_t i = 0; i < 5 and validData == false; i++)
|
||||||
{
|
{
|
||||||
|
@ -408,7 +414,7 @@ void _loop()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FSM_STATE_SD:
|
case FSM_STATE_SD:
|
||||||
debug("set sensor data in webupdater");
|
debug("set sensor data in webupdater if required");
|
||||||
#ifdef WEBUPDATER_FEATURE
|
#ifdef WEBUPDATER_FEATURE
|
||||||
setSensorData(currentSensorData);
|
setSensorData(currentSensorData);
|
||||||
#endif
|
#endif
|
||||||
|
@ -423,7 +429,11 @@ void _loop()
|
||||||
|
|
||||||
//delay(100); // TODO warum hier ein delay?
|
//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[])
|
void logToSerial(float sensorValues[])
|
||||||
|
|
|
@ -55,7 +55,9 @@ void setupWebUpdater(String device, String ip)
|
||||||
#ifdef DEBUG_WINDSPEED_MEASUREMENT
|
#ifdef DEBUG_WINDSPEED_MEASUREMENT
|
||||||
httpServer.on("/measWind", measureWindspeed);
|
httpServer.on("/measWind", measureWindspeed);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_LOGGER
|
||||||
|
httpServer.on("/showlog", showLog);
|
||||||
|
#endif
|
||||||
httpServer.begin();
|
httpServer.begin();
|
||||||
|
|
||||||
debug("HTTPUpdateServer ready!");
|
debug("HTTPUpdateServer ready!");
|
||||||
|
@ -139,7 +141,7 @@ void hb_webstat_send(void)
|
||||||
void resetWifiManager()
|
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\">"
|
"<meta http-equiv=\"refresh\" content=\"20\">"
|
||||||
"</head><body>"
|
"</head><body>"
|
||||||
"Reset WifiManager config.<br>"
|
"Reset WifiManager config.<br>"
|
||||||
|
@ -169,7 +171,7 @@ void measureWindspeed()
|
||||||
float tmp_windspeed = wind_speed();
|
float tmp_windspeed = wind_speed();
|
||||||
digitalWrite(STATUS_LED_PIN, LOW);
|
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>"
|
"</head><body>"
|
||||||
"Windsensor measurement result: " + String(tmp_windspeed) + "<br>"
|
"Windsensor measurement result: " + String(tmp_windspeed) + "<br>"
|
||||||
"</body></html>";
|
"</body></html>";
|
||||||
|
@ -179,3 +181,44 @@ void measureWindspeed()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#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
|
||||||
|
|
Loading…
Reference in a new issue