It is OK to use watchdog on mqtt arduino?


#1

Hello,

It is best practice to use the wachdog fucntion to recover the arduino when it bolck.

today the arduino stuck when arrives to 60000 seconds of use and until go back home was no posibility to restart it.

I just inplement this code, It is OK or really has no vaule on the sketch?

#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include "DHT.h"
#include <avr/wdt.h>
int amarillo = 0;
int blanco = 0;

// WiFi network info.
char ssid[] = “xequebo”;
char wifiPassword[] = “0”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “80”;
char password[] = “0”;
char clientID[] = “0”;

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial
#define DHTPIN 7
#define DHTTYPE DHT11
ESP8266 wifi(&EspSerial);
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
wdt_disable();
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
delay(10);
dht.begin();
// Set ESP8266 baud rate
EspSerial.begin(9600);
delay(10);

Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
wdt_enable(WDTO_8S);
}

void loop()
{
Cayenne.loop();
wdt_reset();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT() {
float h = dht.readHumidity();
float t = dht.readTemperature();
Cayenne.luxWrite(2, analogRead(1));
Cayenne.virtualWrite(4, h, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
Cayenne.virtualWrite(3, t, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(0, millis() / 1000);
}

CAYENNE_IN(12)
{
amarillo = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, 12, 12, amarillo);
digitalWrite(12, amarillo);
}
CAYENNE_IN(13)
{
blanco = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, 13, 13, blanco);
digitalWrite(13, blanco);
}


#2

It seems that the watch dog is working, i am using the millis display to monitor how many time the device is working and I can see droppings to 0 and how the device restart it againg by itself:

on the graph I see how after 9pm the watchdog restart the device when the arduino stuck. Now I can reproduce the stuck situation pressing several times my dashboard the LED on/Off quickly. it seems that the system do not accept too many actions.

in this case the dashboard page reload sometimes work and some times not, but if the arduino device stuck the watchdog is doig its job


#3

Hi tecnopatiaserera,
I’m not sure, but I think your disconnects might be because you are exceeding the rate limits.


#4

Only 4 sensors x 15 seconds are 16 messages x minute. I guess that all the rest ones could come from the actuators and the feedback.