2323
2424#include <Arduino.h>
2525#ifdef ESP8266
26- #include <user_interface.h> // Include this to define rst_info
27-
26+ #include <user_interface.h> // Include this to define rst_info
2827
2928typedef struct rtc_mem {
30- uint32_t version ; // RTC memory version
29+ uint32_t version ; // RTC memory version
3130 uint32_t rebootCount ; // Number of reboots
3231} rtc_mem_t ;
3332
3433// Constructor function that runs during static initialization (before setup)
35- __attribute__((constructor ))
36- void checkrebootcount (){
34+ __attribute__((constructor )) void checkrebootcount () {
3735 Serial .begin (115200 );
38- struct rst_info * resetreason ;
36+ struct rst_info * resetreason ;
3937 rtc_mem_t rtcMem ;
4038 resetreason = ESP .getResetInfoPtr ();
4139 Serial .println ("Reset reason code: " + String (resetreason -> reason ));
@@ -48,9 +46,9 @@ void checkrebootcount(){
4846 rtcMem .version = 0x01 ;
4947 rtcMem .rebootCount = 0 ;
5048 }
51- if (resetreason -> reason != REASON_SOFT_WDT_RST &&
52- resetreason -> reason != REASON_EXCEPTION_RST &&
53- resetreason -> reason != REASON_WDT_RST ) {
49+ if (resetreason -> reason != REASON_SOFT_WDT_RST
50+ && resetreason -> reason != REASON_EXCEPTION_RST
51+ && resetreason -> reason != REASON_WDT_RST ) {
5452 // Not a crash, reset reboot counter
5553 rtcMem .rebootCount = 0 ;
5654 } else {
@@ -75,8 +73,6 @@ void checkrebootcount(){
7573 }
7674 Serial .println ("Reboot Count: " + String (rtcMem .rebootCount ));
7775 ESP .rtcUserMemoryWrite (33 , (uint32_t * )& rtcMem , sizeof (struct rtc_mem ));
78-
79-
8076}
8177
8278#endif
0 commit comments