Error using Whatdog on MKR1000

I'm beginner, I'm trying to program the MKR1000 to read temperature and humidity with Whatdog, but I get the error below. I've downloaded all the libraries I found from AVR and WDT, still giving the error.. Can someone help me.

Erro mesagem:

Temp_HUm_Rele_Whatdog:7:49: error: avr/wdt.h: No such file or directory

#include <avr/wdt.h> //Watch dog timer functions

^

compilation terminated.

exit status 1
avr/wdt.h: No such file or directory

My code:

define BLYNK_PRINT SerialUSB
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>
#include <DHT.h>
#include <avr/wdt.h> //Watch dog timer functions
#include <EEPROM.h> //library for using EEPROM

char auth[] = "0c8a2f2588ed47d5820a911cab879198";
int led = 13;
volatile int wSetting = 1; //variable to store WDT setting, make it volatile since it will be used in ISR

char ssid[] = "xxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxx";

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

#define DHTPIN 2 // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
SerialUSB.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}

void setup()
{
// Debug console
SerialUSB.begin(115200);

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

dht.begin();

// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);

wdt_disable(); //Datasheet recommends disabling WDT right away in case of low probabibliy event
pinMode(led, OUTPUT); //set up the LED pin to output
pinMode(2,INPUT_PULLUP); //setup pin 2 for input since we will be using it with our button
getSettings(); //start serial settings menu to choose WDT setting
//setup the watchdog Timer based on the setting
if(wSetting == 1) setWDT(0b01000000); //set for interrupt
else if(wSetting == 2) setWDT(0b00001000); //set for reset
else setWDT(0b01001000); //set for interrupt and then reset
}

void loop()
{
Blynk.run();
timer.run();
}
if(!digitalRead(2)) { //check if button to reset WDT was pressed
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
wdt_reset(); //Reset the WDT
}
}

//This function gets the WDT setting from the user using Serial comm
void getSettings() {
Serial.begin(57600);
Serial.println("We just started up......");
byte b; //variable to store interrupt / reset tracker
if(EEPROM.get(10, b)) { //check if interrupt occurred before reset
Serial.println("...and an interrupt occurred.....");
b = 0; //reset variable
EEPROM.put(10,b);
}
Serial.println("Select the WDT setting: 1 --> interrupt, 2 --> reset, 3 --> interrupt and reset");
//wait for user to input setting selection
while (!Serial.available()) { }
wSetting = Serial.parseInt(); //get entry and ensure it is valid
if(wSetting < 1 || wSetting > 3) {
wSetting = 1;
}
Serial.print("WDT setting is ");
Serial.println(wSetting);
Serial.println();
Serial.end(); //don't want to mix serial comm and interrupts together
}

/*
void setSleepInterval(byte timer) {
sleep_enable(); //enable the sleep mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN); //set the type of sleep mode. Default is Idle. power down saves the most power
ADCSRA &= ~(1<<ADEN); //Turn off ADC before going to sleep (set ADEN bit to 0). this saves even more power
WDTCSR |= 0b00011000; //Set the WDE bit and then clear it when set the prescaler, WDCE bit must be set if changing WDE bit
WDTCSR = 0b01000000 | timer; //This sets the WDT to the interval specified in the function argument
wdt_reset(); //Reset the WDT
sleep_cpu(); //enter sleep mode. Next code that will be executed is the ISR when interrupt wakes Arduino from sleep
sleep_disable(); //disable sleep mode
ADCSRA |= (1<<ADEN); //Turn the ADC back on
}*/

//this function setups up and starts the watchdog timer
void setWDT(byte sWDT) {
WDTCSR |= 0b00011000;
WDTCSR = sWDT | WDTO_2S; //Set WDT based user setting and for 2 second interval
wdt_reset();
}

//This is the interrupt service routine for the WDT. It is called when the WDT times out and is in interrupt mode.
//This ISR must be in your Arduino sketch or else the WDT will not work correctly
ISR (WDT_vect)
{
digitalWrite(led, HIGH);
if(wSetting == 3) {
byte b = 1;
EEPROM.put(10, b);
}
//wdt_disable();
} // end of WDT_vect

The watchdog code in that sketch is written specifically for the AVR architecture but your MKR1000 is SAMD architecture. There is absolutely no way to make that code work on your MKR1000, no matter how many random libraries you install.

You have two options:

  • Use the code on an AVR microcontroller.
  • Modify the code so that it's compatible with the SAMD architecture.

There are some Arduino libraries that abstract the watchdog timer interface, such as this one:

you'd need to determine whether they expose all the functionality you need. Or you can just study the datasheet for the ATSAMD21G18 microcontroller on your MKR1000 and learn how to use the watchdog timer at a low level, as is done in your sketch for AVR.