add watchdog handling

This commit is contained in:
Wolfgang Hottgenroth 2016-07-12 12:36:50 +02:00
parent 99e4edf762
commit 444ace95e0
2 changed files with 6 additions and 3 deletions

View File

@ -28,8 +28,6 @@ void setup() {
}
void loop() {
wdt_reset();
if (tick.check()) {
Serial << "tick" << endl;
}

View File

@ -7,6 +7,7 @@
#include "mqttclient.h"
#include <avr/wdt.h>
#include <Streaming.h>
#include <WiFi.h>
#include <WiFiUDP.h>
@ -21,6 +22,7 @@ extern Hmi hmi;
static const char MESSAGE_TOPIC[] = "IoT/Monitor/Message";
static const char ALARM_TOPIC[] = "IoT/Monitor/Alarm";
static const char SECONDS_TOPIC[] = "IoT/SecondsSinceMidnight";
static const char WATCHDOG_TOPIC[] = "IoT/Watchdog";
@ -82,6 +84,8 @@ void callback(char* topic, byte* payload, unsigned int length) {
} else if (!strcmp(topic, SECONDS_TOPIC)) {
uint32_t seconds = atol(buffer);
hmi.setSeconds(seconds);
} else if (!strcmp(topic, WATCHDOG_TOPIC)) {
wdt_reset();
} else {
Serial << "Strange, unknown topic received" << endl;
}
@ -176,6 +180,7 @@ void MqttClientNS::exec() {
mqttClient.subscribe(MESSAGE_TOPIC);
mqttClient.subscribe(ALARM_TOPIC);
mqttClient.subscribe(SECONDS_TOPIC);
mqttClient.subscribe(WATCHDOG_TOPIC);
disconnectTime = millis();
mqttClient.publish("IoT/Monitor/Started", "monitor started");
disconnectState = 0;
@ -195,7 +200,7 @@ void MqttClientNS::exec() {
if (disconnectState == 0) {
String msg = String("{ \"metadata\": { \"device\": \"Monitor\" }, \"data\": { \"uptime\": ") + uptime + String("}}");
mqttClient.publish("IoT/Monitor/Heartbeat", (char*)msg.c_str());
mqttClient.publish("IoT/Heartbeat/Monitor", (char*)msg.c_str());
}
}