2

I have a code looping with the help of the dsleep mode. Each time dsleep ends, the init.lua is loaded, does something the goes back to sleep.

Now I want to implement a button to my ESP8266 that will trigger the reset pin. When pushed, my system should enter in a "setup mode", providing AP to do some setup (that part of code is OK).

My problem is: How do I know if the current init was triggered manually (then go to setup mode) or by normal reboot after dsleep?

I'm guessing that there should be two ways doing this:

  1. programmatically: somehow store a meta-global variable changed by the gpio15 trigger in the end of dsleep ...
  2. electronically: hack something to change one pin state when pushing reset button

Any advice?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
bixente57
  • 1,328
  • 4
  • 14
  • 29

3 Answers3

2

I know for a fact that it's possible (without any hacks) with the Arduino IDE with ESP.getResetInfoPtr(). A guy used it here

I don't think it has been enabled in nodemcu firmware.

seblucas
  • 825
  • 1
  • 7
  • 17
  • NodeMCU does have that as pointed out in the other answer, [`node.bootreason`](http://nodemcu.readthedocs.org/en/dev/en/modules/node/#nodebootreason). – Marcel Stör Feb 29 '16 at 18:48
1

You can get the reboot reason by using the node.bootreason() function.

Sample Code is (you can omit any variables after code, reason if you don't need the additional information:

code, reason, exccause, epc1, epc2, epc3, excvaddr, depc = node.bootreason()
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
Adam B
  • 3,775
  • 3
  • 32
  • 42
  • Is there a definition of `exccause`? I could find code and reson, but not the latter. – dda Mar 30 '16 at 06:18
1

This functionality is implemented by Espressif in their SDK:

int reason = ESP.getResetInfoPtr()->reason;


switch (reason) {
    case REASON_DEFAULT_RST:
        // Normal Power up
        break;
    case REASON_WDT_RST:
        break;
    case REASON_EXCEPTION_RST:
        break;
    case REASON_SOFT_WDT_RST:
        break;
    case REASON_SOFT_RESTART:
        break;
    case REASON_DEEP_SLEEP_AWAKE:
        break;
    case REASON_EXT_SYS_RST:
        break;

    default:
        break;
    }
Ali80
  • 6,333
  • 2
  • 43
  • 33