ESP8266 RESET

As often as not, when I reset an ESP8266 by using the system reset call in the SDK, after flashing – for example.

if (strcmp(token, “id”) == 0) {
                    if (isQuery) RESPONSE(“ID=%s\r\n”, sysCfg.base);
                    else if (strlen(strValue)>=2){
                        strcpy(sysCfg.base, strValue);
                        CFG_Save();
                        system_restart();
                    }

The unit does not come out of reset.. the internal startup code will run, maybe there will be a reference to the watchdog – and that’s it. This usually happens after FLASHING the chip.. ie you flash it, you run the code to reset – it won’t.

But otherwise the system_restart works fine.

Anyone have any idea why this should be and how to get around it. I’m not the only one to mention this?

32 thoughts on “ESP8266 RESET

  1. hi
    ets_intr_lock(15); // all intruptt off eset ets Jan 8 2013,rst cause:2, boot
    ets_wdt_disable(); // eset ets Jan 8 2013,rst cause:4, boot

    hier wrtie code cpu work any loop case reset

    ets_intr_unlock(15);
    ets_wdt_enable();

    REANSON_DEFAULT_RST = 0, // normal startup by power on
    REANSON_WDT_RST = 1, // hardware watch dog reset
    // exception reset, GPIO status won’t change
    REANSON_EXCEPTION_RST = 2,
    // software watch dog reset, GPIO status won’t change
    REANSON_SOFT_WDT_RST = 3,
    // software restart ,system_restart , GPIO status won’t change
    REANSON_SOFT_RESTART = 4,
    REANSON_DEEP_SLEEP_AWAKE = 5, // wake up from deep-sleep

    1. This is an OLD post. Resets are generally caused by code taking too long to operate – or running out of RAM as is often the case with that Lua interpreter.

  2. #include
    #include

    // Update these with values suitable for your network.

    const char* ssid = “……………….”;
    const char* password = “……………….”;
    const char* mqtt_server = “iot.eclipse.org”;

    WiFiClient espClient;
    PubSubClient client(espClient);
    long lastMsg = 0;
    char msg[50];
    int value = 0;

    void setup_wifi() {

    delay(10);
    // We start by connecting to a WiFi network
    Serial.println();
    Serial.print(“Connecting to “);
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(“.”);
    }

    Serial.println(“”);
    Serial.println(“WiFi connected”);
    Serial.println(“IP address: “);
    Serial.println(WiFi.localIP());
    }

    void callback(char* topic, byte* payload, unsigned int length) {
    Serial.print(“Message arrived [“);
    Serial.print(topic);
    Serial.print(“] “);
    for (int i = 0; i 2000) {
    lastMsg = now;
    ++value;
    snprintf (msg, 75, “hello world #%ld”, value);
    Serial.print(“Publish message: “);
    Serial.println(msg);
    client.publish(“outTopic”, msg);
    ESP.wdtDisable();
    }
    }

    This is my code how to solve automatically restart wdt in esp . please help me

  3. My esp is automatically reset ets Jan 8 2013,rst cause:4, boot mode:(3,6)

    Exception (9):
    epc1=0x402ÿ2�epc2=0x00000000 epc3=0x00000000 excvaddr=0x40104c27 depc=0x00000000

    ctx: sys
    sp: 3fffe110 end: 3fffffb0 offset: 01a0

    >>>stack>>>
    3fffe2b0: 00000000 00000000 00000000 00000000
    3fffe2c0: 00000000 00000000 00000000 00000000

    (etc et. ED)

    3fffff90: 00000000 3fffdad0 3ffeee38 40203187
    3fffffa0: 3ffe8ca0 40000f49 3fffdab0 40000f49
    <<<stack<<<

    ets Jan 8 2013,rst cause:4, boot mode:(3,6)

    wdt reset
    load 0x4010f000, len 1264, room 16
    tail 0
    chksum 0x0f
    csum 0x0f
    ~ld
    when i upload the my code means after automatically restart the esp 12E how to solve it.please help me.

  4. I was having this issue and added a pullup to GPIO0.
    This appears to have fixed the restart problem after flash for me.

  5. Hi Pete,

    Thanks for your quick reply.

    For 1st one.. I am using GPIO16 to hard reset the ESP by taking it low programmatically. If I don’t do this then my ESP wont reconnect to my Wifi Rotuer on soft reset. This is the same problem I had earlier which got solved only by using GPIO16 connected to RESET. And this works.

    For point 2:
    Check this out:
    http://www.google.co.in/imgres?imgurl=http://img15.hostingpics.net/pics/790940ESP12SCHEMA.jpg&imgrefurl=http://www.esp8266.com/viewtopic.php?p%3D7808&h=319&w=700&tbnid=PBsyDGPRkI_8SM:&docid=iqyq5z4Ss8WsnM&ei=KPnmVembKoyQuQTcgIjwBw&tbm=isch&ved=0CCEQMygFMAVqFQoTCOnP9Pq52McCFQxIjgodXAACfg

    This has a reset circuitary for ESP12.

  6. Hi Abhishek

    I’m a bit confused about GPIO16 as it is just an output – or can be – we used to have it connected to the reset circuit but now it is free and we use it as an optional output… so I don’t see, if you want to use it with reset why you can’t try a 0.1u cap to ground?

    The second point – hmmm, this is a new one on me I’ve not read anything about the need for an external reset. If you find any authoritative looking articles on the subject I’d really like to know about it.

  7. Hi Pete,

    Thanks for all your suggestions.

    I am in need of some serious help. I told you about the reset happening once I do some sparking in my power extension board. I expected it to be my wired connection between GPIO16 and reset pin which was acting as an aerial and catching all sort of noise. I removed and I can see resets stopped happening under the previously mentioned scenario.

    Now I already made a new PCB with a proper connection trace between GPIO16 and RESET. Now I have 2 questions here. Find them below:

    Q1: Do I need to put a small bypass capacitor across GPIO16 and GND in order to suppress any unwanted noise? What i am afraid of is that this time probably my copper trace can pick those nasty noise elements and reset my ESP.

    Q2: I have seen people attaching a reset circuit with 10 K and 0.1uf with the reset pin. This helps resetting the ESP properly by keeping it low for a moment and then making it high. Should I also do this i my case, along with a direct connection between reset and GPIO16. As per my understanding the reset circuitry will save my ESP resetting due to noise picked up by copper trace between GPIO16 and RESET as there will be a 0.1uf bypass capacitor already present.

    Please let me know your opinion.

    Thanks,
    Abhishek

  8. Hi Pete,

    Scenario for reset:

    I have a power extension board which have a UPS on one of the points. I observed a real issue while switching the UPS on. Every time I toggle the UPS switch my ESP resets. Looks like some voltage spike or EMI. Not sure how to solve this. However I do have a real funny solution for this. What I did was wrapped my entire circuit in normal Aluminium foil and that works pretty awesome. I have done this earlier as well where there was a 5V SMPS charging circuit and few sensors in a closed box and that works pretty well too.

    Any thoughts on this ? Also am I the only one facing these critical issues. Maybe I am testing it for too many scenarios..

    1. You’re not alone – I have one board, 3v3 linear regulator with 5v switched – same as my other boards, but I’ve an outside, 5w LED light attached – to a relay again normal relay on my boards – when the relay triggers the first time it jitters – from then on it works just fine – I’m guessing some kind of static build up on the outside light – as I can think of no other reason – so the circuit can be somehow sensitive to this… the only problem with a shielded box is the internal ESP12 aerial of course needs to be out in the open!

  9. Hi Yes Pete. I am using a 5v proper supply and a look.. lm117 3.3 volts and also 470uf smoothing cap along with decoupling caps. I already exploded one of those Chinese adapters so am away from them.

    I feel it is more of a circuit design issue as mine don’t have a ground plane. Need to make a new pcb and test

  10. Hi Pete,

    Thanks for the reply.

    Well for now I am using ESP12 only as a microprocessor which is going to replace my AVR. So I feel it should work as even a reset should not take more than a second. And water level can be monitored easily with such a device.

    Apart from these I had observed some weird self reset issues. I do have a decoupling capacitors of 10uf and 0.1 uf in place next to power supply and also very close to esp vcc pin. But it resets due to emi. I solved it by wrapping my circuit in aluminium foil which works as a shield and prevents EMI. Still am not sure if that is the way to go And have a bit of hesitation using esp in real environment.

    1. What kind of supply are you using? I firstly tried cheap Chinese 3v3 power supplies and found them to be virtually useless for ESP8266-type boards. My solution in all cases is a 3v3 SMT linear regulator on the board with the ESP, fed from a cheap Chinese 5v supply.

  11. Hi Pete,

    Would like to know your opinion on ESP’s usage. I have made a home automation system where I am using ESP12.

    Currently working on a small water level controller for my own apartment. Would you suggest going ahead with ESP in such an environment where continuous operation is required. There will however be a visual intimation for the ESP board to be up and running. Maybe some LEDs. The security guy can anyway verify this and take some action in case something goes wrong. But just would like to know your opinion.

    Thanks.

    1. Abhishek – Carefully programmed in C I believe the boards to be generally reliable – in my case after powerup then every day, I send an MQTT “heartbeat” message to the boards from a central “controller” which is a battery backed-up Raspberry Pi2 – the ESPs have a flashing light on them that alternates every second. If that heartbeat does not arrive, I stop the flashing lights, try again to get the message and if that fails, reboot the board. That seems a reliable way to indicate if there is an issue and attend to it – I hate to use reboot as it’s an admission of failure but for remote units it is better than nothing. I guess it all depends on your application and whether these devices are stand-alone or have some kind of central controller.

      If stand alone you could use some kind of means to tell if they are talking to the outside world – like getting the time – but you don’t mention if you are planning to remote control these or use the WIFI in any way.

  12. Yeah Pete you are right. These are essentially the issues related to negative use cases which areas important as the positive ones. For now I am running a system which is working pretty well for 3-4 weeks.

    I have currently handled all in software so on losing wifi connection and other similar scenarios the code is able to handle it gracefully. I hope that these issues will be solved overtime because that’s what has happened till now.
    I struggled with using Lm35 temperature sensor but then same code in the nightly builds of ID works awesome. Hope to see things getting better.

    About a callback mechanism in case of a system delay caused by a long running operation might not be feasible as in that case code is anyways stuck and we don’t have Java like multithreading available here.

    And yes we can design an external reset circuit via some sort of astable multivibrator feeding power to esp and if esp fails to retrigger it within time out period then it will stop power to esp which will eventually reset the esp. M not an electronics guy.. Maybe we can do something better than that..

  13. Hi Abhishek – general reliability – yes, well I’ve a bunch of ESP-01s, ESP-12s, some ESP-07s and 3 or 4 Node-MCU boards and “generally” I’ve no problem with them – well, I say that after a long learning curve about not doing delays etc… but I did most of my research in the UK where we have stable electricity and you should be able to rely on routers not resetting etc. Here in rural Spain the picture is not quite so glowing – we have power cuts and glitches from time to time so it is here that I’m starting to see issues. I don’t THINK there are any issues with the ESPs as such other than question marks over startup and recovery from WIFI issues. One could easily solve this by using a hardware watchdog to reset them but that’s a crude way, I’d rather get to the bottom of what if anything is wrong and how to get around it….

    1. It would be a lot better if, instead of watchdog issues rebooting the things, if we could actually get a callback to allow us to DO something sensible.

  14. Hi Pete,
    It’s good I found this forum where there is someone so active.

    Well would you like to comment about ESP’s reliability other than the restart issue? I am using it seriously and have simple products running on top of it.

  15. One more thought .. If you use GPIO2 as an OUTPUT, For Example: I used it to play a tone on 5V speaker as an wifi status debug mechanism, then I have seen the behavior where it stucks for no reason. I got the problem because the tone played continuously for me and it was easy to make out. This has also happened with me when I was using ESP01. Same as on ESP12.

    1. Specifically because of issues with GPIO2 I always treat it as GPI2 – and use as an input – with a pullup resistor. A good point however to note.

  16. Hi Pete,

    I do have a similar experience where the device does not work as required on a power up. For me it happens every time I load a new sketch (Am dealing with Arduino). The very first reset by the system once the sketch gets uploaded is fine (this is done by the IDE) but then subsequent ESP.reset() hangs the ESP.

    This essentially does not seem to be a big issue. Looks like it gets stuck in the programming mode. What I do is after every sketch upload I remove the power and also disconnect the ESP from USB to Serial Convertor. Then it works fine 100% times.

    Just another addition .. Till now I had got 100% results after tying GPIO16 to RESET. I tried over night and is still working.

    1. I think there are two separate issues… there is clearly an issue after programming a device – and as you say that is solved by a power or proper reset. However, only yesterday I turned a device on and it sat there… rebooted and it was fine – most of the time that does not happen (and this is with a power supply firing out 5v at 1 amp and that is then fed through a 3v3 linear regulator…) interested to hear other issues people have had at power up and what they were doing with IO pins at the time.

  17. Hi,

    First Thanks a ton. This was a life saving post which gave me a clue to properly RESET my ESP12.

    I was facing really weird issue where my ESP12 wont connect to my WIFI Router after a soft reset. If the WIFI Router is pretty close then it was connecting but not if it was a bit far.

    However, hard reset (powering off/on) worked fine with 100% accuracy. Does anyone know what could of difference in WIFI conenctivity on Hard vs Soft Reset (using ESP.reset() in Arduino Framework)

    Currently I am using GPIO16 (tied to RESET) for hard resetting the ESP. And that works pretty well. Till now no issues/side-effects.

    1. I think you’ll find the reset issue coming up time and time again… I don’t think most of us totally understand what’s happening there. I turned a board on yesterday and it just sat there… turned it off -then on again – fine – and that’s just not good enough…. might be good at some point if Espressif were to do a DEFINITIVE guide to what to do with the various pins (we all have our own ideas) and the difference between the various types of reset.

      Actually – you are right – I’ve treated GPIO16 as a nuisance up to now (accidentally tied it to reset on our boards then realised I could not use it for a port) but maybe that’s the way to do reset as against the system reset function… hmm.. more testing needed.

  18. The bootstrapping values are only loaded up once during a proper power-on (or proper reset by pulling RESET pin low then high? haven’t confirmed). So when you call the restart_system command, it restarts into the bootloading code, uses the previously sampled value of GPIO0 (low for programming that you did), and starts the Serial Bootloader mode.

    So really, it’s more of a soft-reboot than a hardware restart.

    1. THAT’S handy to know – thanks for that. Yes, a reliable full soft reset would be good…I suppose you could always deliberately do what I accidentally did – tie GPIO16 to reset and try to set it as a low output 🙂

      1. You know guys – the more I think about that… if you don’t have a use for GPIO16 – fasten it to reset, when a board comes out of reset – if you could check that it was a “soft-reset” you could force the issue by setting GPIO16 as an output – forcing a “proper” reset… enough people have complained about the soft reset it’s probably worth doing.

        1. Except when it reboots, it’s in the serial bootloader mode, not where your code is running! Best option would be to write your own system_hardreset() function that toggles GPIO16 rather than relying on the SDK provided one. I’ve always made an allowance on my PCBs to connect GPIO16 to the reset pin via an unpopulated resistor footprint, so I might try it out at some point.

          1. Oh it works David – I made a complete fool of myself as Aidan who designed our last board layout had put a link from GPIO16 to reset and I could not understand why it reset every time I tried to set GPIO16 as an output 🙂

  19. Yes, I have noticed it as well. Would love to find an answer or a reliable way to reset.

Comments are closed.