-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for (emergency) OTA mode (#109)
* Add support for emergency OTA mode * Add protection for manual reboot loop
- Loading branch information
Showing
6 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "CrashDetection.h" | ||
|
||
#include <rom/rtc.h> | ||
#include <Arduino.h> | ||
|
||
// positive values indicate a crashing system. negative values a manual reboot loop | ||
RTC_NOINIT_ATTR static int crash_count = 0; | ||
|
||
bool is_crash_mode() { | ||
return (crash_count > MAX_CRASH_COUNT) || (crash_count > -MAX_CRASH_COUNT); | ||
} | ||
|
||
void init_crash_detection() { | ||
// crash reason is not sw reset, so not a crash! | ||
if(rtc_get_reset_reason(0) != 12) { | ||
crash_count = 0; | ||
} else { | ||
++crash_count; | ||
} | ||
} | ||
|
||
int get_crash_count() { | ||
return crash_count; | ||
} | ||
|
||
void reset_crash_count() { | ||
crash_count = 0; | ||
} | ||
|
||
void restart_esp() { | ||
--crash_count; | ||
ESP.restart(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _CRASHDETECTION_H_ | ||
#define _CRASHDETECTION_H_ | ||
|
||
#define MAX_CRASH_COUNT 5 | ||
|
||
bool is_crash_mode(); | ||
void init_crash_detection(); | ||
void restart_esp(); | ||
int get_crash_count(); | ||
void reset_crash_count(); | ||
|
||
#endif // _CRASHDETECTION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters