reworked mqtt for new server + added watchdog

This commit is contained in:
2021-06-04 18:21:52 +02:00
parent 567ffdb490
commit 28662f0289
2 changed files with 107 additions and 70 deletions

View File

@@ -7,6 +7,11 @@
#include <SPI.h>
#include "RF24.h"
#include <Ticker.h>
const uint32_t wdtTimeout = 8388607; //maximum for the ESP8266
uint32_t LastWdgFeeding;
Ticker timer;
/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
@@ -40,6 +45,20 @@ RF24 radio(D4,D8);
byte addresses[][6] = {"1Node","2Node"};
void ICACHE_RAM_ATTR resetModule() {
/*Serial.print("Current time: ");
Serial.println(millis());
Serial.print("Last fed: ");
Serial.println(LastWdgFeeding);*/
//restart if the program hangs for more than 10min...
if (millis() - LastWdgFeeding > 600000) {
Serial.print("Restarting due to watchdog!");
ESP.restart();
}
timer1_write(wdtTimeout);
}
void setup() {
Serial.begin(115200);
@@ -74,6 +93,10 @@ void setup() {
digitalWrite(pinGaragenTorSchalter, HIGH);
TorStatusChanged = true;
timer1_attachInterrupt(resetModule);
timer1_enable(TIM_DIV256, TIM_EDGE, TIM_SINGLE);
timer1_write(wdtTimeout);
}
@@ -140,6 +163,9 @@ if (TorStatusChanged == true) {
//go back to listening
TorStatusChanged = false;
//feed the watchdog...
LastWdgFeeding = millis();
}
@@ -152,6 +178,9 @@ if (TorStatusChanged == true) {
if( radio.available()){
// Variable for the received timestamp
//feed the watchdog...
LastWdgFeeding = millis();
while (radio.available()) { // While there is data ready
len = radio.getDynamicPayloadSize();
radio.read( &gotmsg, len ); // Get the payload
@@ -191,7 +220,7 @@ if (TorStatusChanged == true) {
}
}
/****************** Control Logic ***************************/
/****************** Control Logic ***************************/
if ((digitalRead(pinStatusGaragenTor1) != TorStatus1)||(digitalRead(pinStatusGaragenTor2) != TorStatus2)) {
TorStatus1 = digitalRead(pinStatusGaragenTor1);
TorStatus2 = digitalRead(pinStatusGaragenTor2);