Hello everyone,
I am using Arduino Mega and Wifi shield. I am using CC3000 Adafruit example from the blynk examples and everything works perfect.
Sometimes Arduino gets offline (it simply hangs). If the connection is out - for more than 30 secs- , I need to program Arduino to be able to reset itself.
I knew that one rigid way of doing this is through Watchdog timer. I also read through Arduino forums, how to get the wdt to work for more than 8 seconds. but due to my limited programming capabilities, I don’t know where to integrate this in the blynk example.
If you please could guide me, how to program my Arduino correctly (What am I missing in the code? What to add?), I would be so grateful,
Here is my best code:
` #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
// These are the interrupt and control pins for СС3000
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
#include <SPI.h>
#include <Adafruit_CC3000.h>
#include <BlynkSimpleCC3000.h>
#include <avr/wdt.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "blabla";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "bla", "bla", WLAN_SEC_WPA2);
}
void loop()
{
if (Blynk.connected()){
Blynk.run();
}
else {
myWatchDogEnable(0b100001); //8 seconds
myWatchDogEnable(0b100001); //8 seconds
myWatchDogEnable(0b100001); //8 seconds
myWatchDogEnable(0b100001); //8 seconds
}
}
void myWatchDogEnable(const byte interval){
MCUSR=0;
WDTCSR|=0b00011000; //set WDCE, WDE
WDTCSR=0b01000000|interval; //set WDIE & delay
wdt_reset();
Blynk.run();
}
ISR(WDT_vect){
wdt_disable();
}`