Restart Arduino weekly, but not if triggered
This commit is contained in:
parent
a6befca199
commit
45a2117858
|
@ -15,7 +15,8 @@
|
||||||
#define WATER_THRESHOLD 750
|
#define WATER_THRESHOLD 750
|
||||||
#define SENSE_THRESHOLD 100
|
#define SENSE_THRESHOLD 100
|
||||||
|
|
||||||
#define MESSAGE_INTERVAL 1000 * 60 * 50 // 50 minutes
|
#define MESSAGE_INTERVAL 1000 * 60 * 20 // 20 minutes
|
||||||
|
#define RESTART_INTERVAL 1000 * 60 * 60 * 24 * 7 // 7 days
|
||||||
|
|
||||||
WiFiClient wifiClient;
|
WiFiClient wifiClient;
|
||||||
MqttClient mqttClient(wifiClient);
|
MqttClient mqttClient(wifiClient);
|
||||||
|
@ -144,15 +145,24 @@ void loop() {
|
||||||
static unsigned long last_pos_message = 0;
|
static unsigned long last_pos_message = 0;
|
||||||
static unsigned long last_neg_message = 0;
|
static unsigned long last_neg_message = 0;
|
||||||
static unsigned long last_sense_message = 0;
|
static unsigned long last_sense_message = 0;
|
||||||
|
static bool hasTriggered = false;
|
||||||
|
|
||||||
bool leakDetected = sampleWater();
|
bool leakDetected = sampleWater();
|
||||||
bool cableDetected = senseCable();
|
bool cableDetected = senseCable();
|
||||||
|
|
||||||
if (leakDetected) {
|
if (leakDetected) {
|
||||||
relayOff();
|
relayOff();
|
||||||
|
hasTriggered = true;
|
||||||
Serial.println("Leak detected!");
|
Serial.println("Leak detected!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!hasTriggered && millis() > RESTART_INTERVAL) {
|
||||||
|
Serial.println("Weekly restarting Arduino...");
|
||||||
|
relayOff();
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
mqttClient.poll();
|
mqttClient.poll();
|
||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user