Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define WATCHDOG_TIMEOUT_S 3
- hw_timer_t * watchDogTimer = NULL;
- void IRAM_ATTR watchDogInterrupt() {
- Serial.println("reboot");
- ESP.restart();
- }
- void watchDogRefresh()
- {
- timerWrite(watchDogTimer, 0); //reset timer (feed watchdog)
- }
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- Serial.println("Watchdog sketch start");
- watchDogTimer = timerBegin(2, 80, true);
- timerAttachInterrupt(watchDogTimer, &watchDogInterrupt, true);
- timerAlarmWrite(watchDogTimer, WATCHDOG_TIMEOUT_S * 1000000, false);
- timerAlarmEnable(watchDogTimer);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- for (int i = 0; i < 10; i++) {
- Serial.print("test: ");
- Serial.println(i);
- watchDogRefresh();
- if (i == 8) {
- delay(4000); // terdelay karena fungsi watchDogRefresh() tidak di peroleh selama 3 detik
- }
- delay(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement