Compare commits
3 commits
9a920aeb88
...
1f347582b0
Author | SHA1 | Date | |
---|---|---|---|
|
1f347582b0 | ||
|
0f6934f4a1 | ||
|
a05af95d51 |
2 changed files with 50 additions and 21 deletions
|
@ -12,7 +12,7 @@
|
||||||
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
|
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
|
||||||
#define RESET_ESP_TIME_INTERVAL_MS (60*60*12*1000) // reset every 12 hours
|
#define RESET_ESP_TIME_INTERVAL_MS (60*60*12*1000) // reset every 12 hours
|
||||||
#define WIND_SENSOR_MEAS_TIME_S 15
|
#define WIND_SENSOR_MEAS_TIME_S 15
|
||||||
#define WATCHDOG_TIMEOUT_MS 30000
|
#define WATCHDOG_TIMEOUT_MS WDTO_8S // Look at Esp.h for further possible time declarations
|
||||||
#define WIFI_CHECK_INTERVAL_MS 120000
|
#define WIFI_CHECK_INTERVAL_MS 120000
|
||||||
#define INFLUXDB_TIMEOUT_MS 1000
|
#define INFLUXDB_TIMEOUT_MS 1000
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
// Standard ESP8266 libs from project folder
|
// Standard ESP8266 libs from project folder
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESP8266WiFiType.h>
|
||||||
|
|
||||||
|
#include <esp.h>
|
||||||
|
|
||||||
#include <WiFiClient.h> // WiFiClient
|
#include <WiFiClient.h> // WiFiClient
|
||||||
|
|
||||||
|
@ -77,6 +80,10 @@ void debug(String x) {
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
#ifdef ENABLE_WATCHDOG
|
||||||
|
//wdt_disable();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(SERIAL_FEATURE)
|
#if defined(DEBUG) || defined(SERIAL_FEATURE)
|
||||||
Serial.begin(SERIAL_BAUD_RATE);
|
Serial.begin(SERIAL_BAUD_RATE);
|
||||||
#endif
|
#endif
|
||||||
|
@ -132,8 +139,11 @@ void setup() {
|
||||||
#else // not in battery mode
|
#else // not in battery mode
|
||||||
|
|
||||||
#ifdef ENABLE_WATCHDOG
|
#ifdef ENABLE_WATCHDOG
|
||||||
|
wdt_disable();
|
||||||
|
wdt_reset();
|
||||||
// Enable the internal watchdog
|
// Enable the internal watchdog
|
||||||
ESP.wdtEnable(WATCHDOG_TIMEOUT_MS);
|
wdt_enable(WATCHDOG_TIMEOUT_MS);
|
||||||
|
debug("Watchdog enabled");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -252,7 +262,6 @@ float readSensors(uint8_t s) {
|
||||||
|
|
||||||
void wifiConnectionCheck() {
|
void wifiConnectionCheck() {
|
||||||
|
|
||||||
/*
|
|
||||||
if ((wifi_check_interval_counter + WIFI_CHECK_INTERVAL_MS) > millis()) {
|
if ((wifi_check_interval_counter + WIFI_CHECK_INTERVAL_MS) > millis()) {
|
||||||
// if check interval is not exceeded abort check
|
// if check interval is not exceeded abort check
|
||||||
return;
|
return;
|
||||||
|
@ -265,29 +274,32 @@ void wifiConnectionCheck() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wifi_reconnect_cnt++;
|
// TODO Was muss hier getan werden?
|
||||||
|
|
||||||
debug("no wifi connection, try to reconnect " + String(wifi_reconnect_cnt));
|
}
|
||||||
|
|
||||||
WiFi.disconnect();
|
#ifdef DISABLE_WIFIMANAGER
|
||||||
WiFi.mode(WIFI_OFF);
|
void wifi_disconnected(WiFiEvent_t event) {
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
|
|
||||||
#ifdef WEBUPDATER_FEATURE
|
|
||||||
setWifiReconnectCnt(wifi_reconnect_cnt);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (wifi_reconnect_cnt >= 5) {
|
if (wifi_reconnect_cnt >= 5) {
|
||||||
debug("\nReboot");
|
|
||||||
|
debug("\nReboot, to much reconnects to wifi done before");
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
debug("no wifi connection, try to reconnect " + String(wifi_reconnect_cnt));
|
||||||
|
|
||||||
|
wifi_reconnect_cnt++;
|
||||||
wifiConnect();
|
wifiConnect();
|
||||||
|
|
||||||
//initWifiBasedSW();
|
#ifdef WEBUPDATER_FEATURE
|
||||||
|
setWifiReconnectCnt(wifi_reconnect_cnt);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//*************************************************************************//
|
//*************************************************************************//
|
||||||
|
|
||||||
|
@ -318,7 +330,7 @@ void wifiConnect() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // DISABLE_WIFIMANAGER
|
#else // DISABLE_WIFIMANAGER is defined
|
||||||
|
|
||||||
if (!WiFi.config(local_IP, gateway, subnet)) {
|
if (!WiFi.config(local_IP, gateway, subnet)) {
|
||||||
debug("Failed to set IP configuration");
|
debug("Failed to set IP configuration");
|
||||||
|
@ -326,6 +338,9 @@ void wifiConnect() {
|
||||||
debug("Successful set IP configuration");
|
debug("Successful set IP configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bind the check function to the disconnected wifi event
|
||||||
|
WiFi.onEvent(wifi_disconnected, WIFI_EVENT_STAMODE_DISCONNECTED);
|
||||||
|
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASSWD);
|
WiFi.begin(WIFI_SSID, WIFI_PASSWD);
|
||||||
WiFi.setAutoReconnect(true);
|
WiFi.setAutoReconnect(true);
|
||||||
|
|
||||||
|
@ -357,15 +372,15 @@ void criticalBatCheck() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
#ifdef ENABLE_WATCHDOG
|
|
||||||
ESP.wdtFeed();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BATTERY_POWERED
|
#ifdef BATTERY_POWERED
|
||||||
delay(50);
|
delay(50);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#else
|
#else // not in BATTERY_POWERED mode
|
||||||
|
|
||||||
|
#ifdef ENABLE_WATCHDOG
|
||||||
|
WDT_FEED();
|
||||||
|
#endif
|
||||||
|
|
||||||
// call fsm loop function
|
// call fsm loop function
|
||||||
_fsm_loop();
|
_fsm_loop();
|
||||||
|
@ -389,6 +404,9 @@ void _fsm_loop()
|
||||||
update_webserver_cnt = millis();
|
update_webserver_cnt = millis();
|
||||||
doWebUpdater();
|
doWebUpdater();
|
||||||
}
|
}
|
||||||
|
#ifdef ENABLE_WATCHDOG
|
||||||
|
WDT_FEED();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HTTP_CALL_SEND_JSON_DATA
|
#ifdef HTTP_CALL_SEND_JSON_DATA
|
||||||
|
@ -401,6 +419,9 @@ void _fsm_loop()
|
||||||
http_call_send_json_data_cnt = millis();
|
http_call_send_json_data_cnt = millis();
|
||||||
http_call_send_json_data();
|
http_call_send_json_data();
|
||||||
}
|
}
|
||||||
|
#ifdef ENABLE_WATCHDOG
|
||||||
|
WDT_FEED();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (fsm_state)
|
switch (fsm_state)
|
||||||
|
@ -604,6 +625,10 @@ void _fsm_loop()
|
||||||
// Send HTTP GET request
|
// Send HTTP GET request
|
||||||
int httpResponseCode = http.GET();
|
int httpResponseCode = http.GET();
|
||||||
|
|
||||||
|
#ifdef ENABLE_WATCHDOG
|
||||||
|
WDT_FEED();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (httpResponseCode > 0) {
|
if (httpResponseCode > 0) {
|
||||||
String response = http.getString();
|
String response = http.getString();
|
||||||
debug("http response code: " + String(httpResponseCode) + " = " + response);
|
debug("http response code: " + String(httpResponseCode) + " = " + response);
|
||||||
|
@ -743,6 +768,10 @@ void http_call_send_json_data()
|
||||||
// Send HTTP GET request
|
// Send HTTP GET request
|
||||||
int httpResponseCode = http.GET();
|
int httpResponseCode = http.GET();
|
||||||
|
|
||||||
|
#ifdef ENABLE_WATCHDOG
|
||||||
|
WDT_FEED();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (httpResponseCode > 0) {
|
if (httpResponseCode > 0) {
|
||||||
String response = http.getString();
|
String response = http.getString();
|
||||||
debug("http response code: " + String(httpResponseCode) + " = " + response);
|
debug("http response code: " + String(httpResponseCode) + " = " + response);
|
||||||
|
|
Loading…
Reference in a new issue