Trying to reconnect when there's no network connection. Reboots if connection is not established for a while
This commit is contained in:
@@ -3,6 +3,10 @@
|
|||||||
#include <ModbusIP_ESP8266.h>
|
#include <ModbusIP_ESP8266.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
// After how much time without connection we will
|
||||||
|
// reboot (in millis)
|
||||||
|
#define NON_CONNECTED_REBOOT_TIMEOUT 60000
|
||||||
|
|
||||||
#define DHTPIN 5
|
#define DHTPIN 5
|
||||||
#define DHTTYPE DHT22
|
#define DHTTYPE DHT22
|
||||||
#define READ_INTERVAL 100
|
#define READ_INTERVAL 100
|
||||||
@@ -66,6 +70,7 @@ void UpdateDHTData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long last_read = 0;
|
unsigned long last_read = 0;
|
||||||
|
unsigned long last_connected = 0;
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
@@ -78,4 +83,16 @@ void loop()
|
|||||||
mb.task();
|
mb.task();
|
||||||
mb.Hreg(REGISTER_CURRENT_TEMP, cur_t);
|
mb.Hreg(REGISTER_CURRENT_TEMP, cur_t);
|
||||||
mb.Hreg(REGISTER_CURRENT_HUM, cur_hum);
|
mb.Hreg(REGISTER_CURRENT_HUM, cur_hum);
|
||||||
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
WiFi.reconnect();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
last_connected = current;
|
||||||
|
}
|
||||||
|
if (current < last_connected || current - last_connected > NON_CONNECTED_REBOOT_TIMEOUT)
|
||||||
|
{
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user