Fix keepalive handling...
parent
281c071ba5
commit
0310b4fa87
|
@ -29,6 +29,9 @@ void SpejsNode::init() {
|
|||
|
||||
registerEndpoint("$implementation", new ImplementationEndpoint());
|
||||
|
||||
// Keepalive Timer initialization
|
||||
keepaliveTimer.initializeMs(10000, TimerDelegate(&SpejsNode::keepAliveHandler, this)).start();
|
||||
|
||||
loadJSON();
|
||||
}
|
||||
|
||||
|
@ -51,9 +54,14 @@ void SpejsNode::loadJSON() {
|
|||
|
||||
void SpejsNode::keepAliveHandler() {
|
||||
static int failureCounter = 0;
|
||||
|
||||
if(mqtt.getConnectionState() != eTCS_Connected) {
|
||||
Serial.println("Reconnecting");
|
||||
if(!WifiStation.isConnected()) {
|
||||
Serial.println("keepalive: Network reconnect");
|
||||
if(failureCounter++ < 5)
|
||||
WifiStation.connect();
|
||||
else
|
||||
System.restart();
|
||||
} else if(mqtt.getConnectionState() != eTCS_Connected) {
|
||||
Serial.println("keepalive: MQTT reconnect");
|
||||
if(failureCounter++ < 5)
|
||||
onConnected();
|
||||
else
|
||||
|
@ -62,21 +70,13 @@ void SpejsNode::keepAliveHandler() {
|
|||
failureCounter = 0;
|
||||
|
||||
uint8_t mode;
|
||||
if(rboot_get_last_boot_mode(&mode)) {
|
||||
if(mode == MODE_TEMP_ROM) {
|
||||
rboot_set_current_rom(currentSlot);
|
||||
Serial.println("Successfuly connected, accepting temp rom");
|
||||
} else {
|
||||
//Serial.printf("Not a TEMP ROM boot: %d\r\n", mode);
|
||||
}
|
||||
} else {
|
||||
//Serial.println("No boot mode info");
|
||||
if(rboot_get_last_boot_mode(&mode) && mode == MODE_TEMP_ROM) {
|
||||
rboot_set_current_rom(currentSlot);
|
||||
Serial.println("Successfuly connected, accepting temp rom");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#define DEV_TOPIC(t) (TOPIC_PREFIX + deviceID + "/" + t)
|
||||
|
||||
inline String SpejsNode::DEV_TOPIC(String t) {
|
||||
return TOPIC_PREFIX + deviceID + "/" + t;
|
||||
}
|
||||
|
@ -129,9 +129,6 @@ void SpejsNode::onConnected() {
|
|||
|
||||
// mDNS initialization
|
||||
initializeMDNS();
|
||||
|
||||
// Keepalive Timer initialization
|
||||
keepaliveTimer.initializeMs(10000, TimerDelegate(&SpejsNode::keepAliveHandler, this)).start();
|
||||
}
|
||||
|
||||
void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)
|
||||
|
|
Loading…
Reference in New Issue