Last active
April 28, 2018 13:40
-
-
Save latonita/51f2c3d138b0d424debce92a80413cbd to your computer and use it in GitHub Desktop.
Count esp8266 reboots
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
#include "Arduino.h" | |
#define RTC_MARKER 0x1234 | |
unsigned int marker = 0; | |
unsigned int reboots = 0; | |
void setup() { | |
// initialize LED digital pin as an output. | |
pinMode(LED_BUILTIN, OUTPUT); | |
Serial.begin(74880); | |
ESP.rtcUserMemoryRead(0, &marker, sizeof(marker)); | |
if (marker != RTC_MARKER) { | |
// first reboot | |
marker = RTC_MARKER; | |
reboots = 0; | |
ESP.rtcUserMemoryWrite(0, &marker,sizeof(marker)); | |
} else { | |
// read count of reboots | |
ESP.rtcUserMemoryRead(sizeof(marker), &reboots, sizeof(reboots)); | |
} | |
reboots++; | |
ESP.rtcUserMemoryWrite(sizeof(marker), &reboots, sizeof(reboots)); | |
Serial.printf("Number of reboots : %d\r\n", reboots); | |
if (reboots == 10) { | |
Serial.println("Welcome, 10th visior =)"); | |
} | |
delay(2000); | |
// turn the LED on (HIGH is the voltage level) | |
digitalWrite(LED_BUILTIN, HIGH); | |
// wait for a second | |
delay(1000); | |
// turn the LED off by making the voltage LOW | |
digitalWrite(LED_BUILTIN, LOW); | |
// wait for a second | |
delay(1000); | |
ESP.deepSleep(RF_DISABLED); | |
} | |
void loop() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment