diff --git a/firmware/config.h b/firmware/config.h
index 8889ee7..288e9ee 100644
--- a/firmware/config.h
+++ b/firmware/config.h
@@ -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 600000
#define ENERGY_SAVING_ITERATIONS 30
diff --git a/firmware/firmware.ino b/firmware/firmware.ino
index 1e15453..a594c09 100644
--- a/firmware/firmware.ino
+++ b/firmware/firmware.ino
@@ -35,17 +35,18 @@ float (*sensors[VALUES])() = {};
uint32_t update_sensor_cnt = 0;
uint32_t update_webserver_cnt = 0;
uint32_t update_windspeed_exceed_cnt = 0;
+uint32_t wifi_check_interval_counter = 0;
const String wifiName = "oko-weather-" + DEVICE_NAME;
-uint32_t wifi_check_interval_counter = millis();
-
WiFiManager wifiManager;
uint8_t fsm_state = FSM_STATE_WU;
uint8_t sensor_cnt = 0;
+boolean validData = false;
+
//*************************************************************************//
void debug(String x)
@@ -173,7 +174,7 @@ void initSensors()
void wifiConnectionCheck()
{
- if (wifi_check_interval_counter + WIFI_CHECK_INTERVAL_MS > millis() or WiFi.status() == WL_CONNECTED)
+ if ((wifi_check_interval_counter + WIFI_CHECK_INTERVAL_MS) > millis() or WiFi.status() == WL_CONNECTED)
{
// if check interval is not exceeded abort check
return;
@@ -252,33 +253,22 @@ void loop()
// Needed to give WIFI time to function properly
delay(DELAY_LOOP_MS);
- update_sensor_cnt == millis();
-
-#ifdef WEBUPDATER_FEATURE
- update_webserver_cnt == millis();
-#endif
-
-#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
- update_windspeed_exceed_cnt == millis();
-#endif
-
}
//*************************************************************************//
void _loop()
{
- boolean validData = false;
switch (fsm_state)
{
case FSM_STATE_WU:
- debug("web updater call if required");
+ //debug("web updater call if required");
#ifdef WEBUPDATER_FEATURE
- if (update_webserver_cnt + (UPDATE_WEBSERVER_INTVERVAL_S * 1000) <= millis())
+ if ((update_webserver_cnt + (UPDATE_WEBSERVER_INTVERVAL_S * 1000)) <= millis())
{
- debug("web updater call");
+ //debug("web updater call");
update_webserver_cnt = millis();
doWebUpdater();
}
@@ -289,49 +279,20 @@ void _loop()
case FSM_STATE_WSE:
debug("wind speed exceeded check if required");
#ifdef HTTP_CALL_ON_WINDSPEED_EXCEED
- if (update_windspeed_exceed_cnt + (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000) <= millis())
+ if ((update_windspeed_exceed_cnt + (HTTP_CALL_ON_WINDSPEED_INTERVAL_S * 1000)) <= millis())
{
- debug("reading wind sensor because of exceed call functionality");
- if (sensors[SENSOR_WINDSPEED])
- {
- // read from windspeed sensorSTATUS_LED_PIN
- digitalWrite(STATUS_LED_PIN, HIGH);
- currentSensorData[SENSOR_WINDSPEED] = sensors[SENSOR_WINDSPEED]();
- digitalWrite(STATUS_LED_PIN, LOW);
-
- if (currentSensorData[SENSOR_WINDSPEED] >= HTTP_CALL_ON_WINDSPEED_EXCEED_MPS)
- {
- digitalWrite(STATUS_LED_PIN, HIGH);
-
- // call the url HTTP_CALL_ON_WINDSPEED_URL
- WiFiClient client;
- HTTPClient http;
-
- http.begin(client, String(HTTP_CALL_ON_WINDSPEED_URL).c_str());
- // Send HTTP GET request
- int httpResponseCode = http.GET();
-
- if (httpResponseCode > 0) {
- String response = http.getString();
- debug("http response code: " + String(httpResponseCode) + " = " + response);
- // TODO handle response
- }
-
- http.end();
- debug("Called windspeed exceed callout");
- digitalWrite(STATUS_LED_PIN, LOW);
- }
- } else {
- currentSensorData[SENSOR_WINDSPEED] = nan("no value");
- }
+ debug("reading wind sensor exceed");
+
update_windspeed_exceed_cnt = millis();
+
+ readWindSpeedExceed();
}
#endif
fsm_state = FSM_STATE_RS;
break;
case FSM_STATE_RS:
- debug("reset time check if required");
+ //debug("reset time check if required");
#ifdef RESET_ESP_TIME_INTERVAL
// if millis() reached interval restart ESP
if (RESET_ESP_TIME_INTERVAL_MS <= millis())
@@ -345,15 +306,15 @@ void _loop()
break;
case FSM_STATE_WS:
- debug("disable measure of wind speed if required");
+ //debug("disable measure of wind speed if required");
#ifdef defined(BATTERY_POWERED) && defined(SENSOR_WIND)
if (energySavingMode() == 1) {
// Disable expensive tasks
sensors[SENSOR_WINDSPEED] = 0;
- debug("read of wind sensor because of low battery disabled");
+ //debug("read of wind sensor because of low battery disabled");
} else {
sensors[SENSOR_WINDSPEED] = &wind_speed;
- debug("read of wind sensor because of high battery enabled");
+ //debug("read of wind sensor because of high battery enabled");
}
#endif
sensor_cnt = 0;
@@ -361,8 +322,8 @@ void _loop()
break;
case FSM_STATE_US:
- debug("read sensor data check");
- if (update_sensor_cnt + (UPDATE_SENSOR_INTERVAL_S * 1000) <= millis())
+ //debug("read sensor data check");
+ if ((update_sensor_cnt + (UPDATE_SENSOR_INTERVAL_S * 1000)) <= millis())
{
debug("read sensor data " + String(sensor_cnt));
if (sensors[sensor_cnt]) {
@@ -401,11 +362,15 @@ void _loop()
{
if (currentSensorData[i] != 0)
{
- // send data only if valid data is available
- pushToInfluxDB(DEVICE_NAME, currentSensorData);
validData = true;
}
}
+
+ if (validData == true)
+ {
+ // send data only if valid data is available
+ pushToInfluxDB(DEVICE_NAME, currentSensorData);
+ }
#endif
fsm_state = FSM_STATE_SD;
break;
@@ -427,12 +392,52 @@ void _loop()
//delay(100); // TODO warum hier ein delay?
//debug("FSM state = " + String(fsm_state));
- if (fsm_state == FSM_STATE_WU)
+ /*if (fsm_state == FSM_STATE_WU)
{
debug("----------");
+ }*/
+}
+
+//*************************************************************************//
+
+void readWindSpeedExceed()
+{
+ if (sensors[SENSOR_WINDSPEED])
+ {
+ // read from windspeed sensorSTATUS_LED_PIN
+ digitalWrite(STATUS_LED_PIN, HIGH);
+ currentSensorData[SENSOR_WINDSPEED] = sensors[SENSOR_WINDSPEED]();
+ digitalWrite(STATUS_LED_PIN, LOW);
+
+ if (currentSensorData[SENSOR_WINDSPEED] >= HTTP_CALL_ON_WINDSPEED_EXCEED_MPS)
+ {
+ digitalWrite(STATUS_LED_PIN, HIGH);
+
+ // call the url HTTP_CALL_ON_WINDSPEED_URL
+ WiFiClient client;
+ HTTPClient http;
+
+ http.begin(client, String(HTTP_CALL_ON_WINDSPEED_URL).c_str());
+ // Send HTTP GET request
+ int httpResponseCode = http.GET();
+
+ if (httpResponseCode > 0) {
+ String response = http.getString();
+ debug("http response code: " + String(httpResponseCode) + " = " + response);
+ // TODO handle response
+ }
+
+ http.end();
+ debug("Called windspeed exceed callout");
+ digitalWrite(STATUS_LED_PIN, LOW);
+ }
+ } else {
+ currentSensorData[SENSOR_WINDSPEED] = nan("no value");
}
}
+//*************************************************************************//
+
void logToSerial(float sensorValues[])
{
Serial.println("");
@@ -446,3 +451,5 @@ void logToSerial(float sensorValues[])
Serial.println("Bat charge state: " + String(sensorValues[SENSOR_BATCHARGESTATE]));
Serial.println("Energy saving: " + String(sensorValues[SENSOR_ESAVEMODE]));
}
+
+//*************************************************************************//
diff --git a/firmware/webUpdater.ino b/firmware/webUpdater.ino
index ef601c2..1260345 100644
--- a/firmware/webUpdater.ino
+++ b/firmware/webUpdater.ino
@@ -101,7 +101,7 @@ void showHTMLMain(void)
#ifdef HOMEBRIDGE_WEBSTAT
"
homebridge websatt
"
#endif
-"