Hello friends of excited electrons,
I’m using the ESP8266-07 with the Arduino library.
I would like to distinguish between a power-on reset and an external-reset with a button.
Reset (RST) pin of ESP8266 is pulled up to VCC with 10k. If the button is pressed it’s tied to GND.
So I searched for a while in the web and found following solution:
#include <Arduino.h>
extern "C" {
#include <user_interface.h>
}
void setup() {
rst_info *resetInfo;
Serial.begin(9600);
resetInfo = ESP.getResetInfoPtr();
Serial.println((*resetInfo).reason);
}
void loop() {
// put your main code here, to run repeatedly:
}
However I get always reset code 6, independent of if I unplug (and replug) power or push the button.
I've awaited, that I get reset code 0 if the device is powered up.
https://github.com/esp8266/Arduino/blob/master/tools/sdk/include/user_interface.h
enum rst_reason {
REASON_DEFAULT_RST = 0, /* normal startup by power on */
REASON_WDT_RST = 1, /* hardware watch dog reset */
REASON_EXCEPTION_RST = 2, /* exception reset, GPIO status won’t change */
REASON_SOFT_WDT_RST = 3, /* software watch dog reset, GPIO status won’t change */
REASON_SOFT_RESTART = 4, /* software restart ,system_restart , GPIO status won’t change */
REASON_DEEP_SLEEP_AWAKE = 5, /* wake up from deep-sleep */
REASON_EXT_SYS_RST = 6 /* external system reset */
};
Now I'm sad
What am I doing wrong?
Software Versions:
Arduino IDE: 1.6.13
Board: ESP8266 version 2.3.0
EDIT: sry for misleadig title. "getResetReason()" is also a method which returns a human readable representation of reset code. However its derived from rst_info and yields the same wrong result.