logo elektroda
logo elektroda
X
logo elektroda

ESP8266 ESP12 Fails to connect to router after hanging up - power consumption

MichałS 1197 14
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18004814
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    A recorder based on an ESP12, an OLED and an INA measurement amplifier. The ESP12 runs on NODEMCU firmware and the program code was written in LUA.

    The logger worked for a few days then suddenly stopped logging (sending data to the server). After cutting the power for a while everything returned to normal, but the logger would not connect to the router. A characteristic feature was the increased current consumption. After re-uploading the same firmware and "ini.lua" file, the recorder came to life and is working correctly.

    What could have been the cause? It wasn't a software crash because logs were flying in the background indicating that there was no WiFi and a reconnect attempt and the OLED was displaying results normally. It wasn't a simple hang-up either, as voltage restarts didn't help. What else was peculiar was the power consumption was exactly as it is now when connecting to the router. Presumably there was a jamming/unprogramming of the radio part of the module ?
  • ADVERTISEMENT
  • #2 18004905
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    Does the script in LUA write data to a file ?
  • #3 18004911
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    Yes; energy production is recorded.
  • ADVERTISEMENT
  • Helpful post
    #4 18004926
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    It is likely that the LUA file was corrupted during the save operation. If this happens again, load the file and compare it with the original one.
    I don't know how it is in ESP8266 but a similar error occurs in ESP32. During certain operations, data cannot be written to the file.
  • ADVERTISEMENT
  • Helpful post
    #5 18005265
    Anonymous
    Level 1  
  • #6 18005745
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    Actually a bit out of character.... It wasn't a simple 'hang-up' of the program because the measurement and results display part worked correctly before and after the restart. The radio, on the other hand, did not work; it simply 'jammed something' at some point. It did not hang up despite restarting and disconnecting the power supply, but the recorder was successfully brought back to life by reprogramming the firmware + init.lua file
  • #7 18005748
    Anonymous
    Level 1  
  • #8 18006041
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    ESP12 module
  • #9 18572884
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    Continuing the theme;
    NodeMCU firmware provides 4 power saving modes: NONE_SLEEP - no sleep at all, 70mA current consumption; MODEM_SLEEP - saving at the expense of switching off the radio, 20mA consumption; LIGHT_SLEEP - as above + CPU load reduction, 15mA current consumption; DEEP_SLEEP - complete sleep.

    In the project the ESP8266 is counting pulses all the time so DEEP_SLEEP mode is out, and in LIGHT_SLEEP unfortunately it consumes the battery too quickly, do you have any idea how to reduce power consumption without DEEP_SLEEP?
  • Helpful post
    #10 18572926
    Anonymous
    Level 1  
  • #11 18575170
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    Thank you for the attached material.
    I don't know to what extent the sleep modes described in the Espressif note coincide with those introduced in the NodeMCU firmware: https://nodemcu.readthedocs.io/en/latest/modules/wifi/#wifistasleeptype

    The fact is that MODEM_SLEEP reduces the current consumption to around 20mA, and LIGHT_SLEEP by a few more mA. However, they are not 2mA.
  • #12 18575192
    Anonymous
    Level 1  
  • #13 18575777
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    NodeMCU is also firmware for ESP modules, please see here: https://www.nodemcu.com/index_en.html Firmware can be uploaded to a module, e.g. ESP12 or ESP07, and the program can be written in Lua (ala Phyton).

    Regarding the reduced power consumption modes, I think it coincides with the Espressif description. In MODEM mode the power consumption is as in the document, unfortunately in LIGHT mode several times higher. Perhaps this is because the programme is running several timers.
  • ADVERTISEMENT
  • #14 18575822
    Anonymous
    Level 1  
  • #15 18578096
    MichałS
    Level 35  
    Posts: 2653
    Help: 254
    Rate: 663
    So if the circuit is working and the difference between MODEM and LIGHT sleep is small then the contribution of LIGHT sleep is also small. I'll check how the module behaves with a simple program, where basically there will only be the activation of a given sleep mode, this will give an indication of what current consumption can be expected.

Topic summary

✨ The discussion revolves around an ESP8266 ESP12-based data logger that experienced connectivity issues with a router after a period of normal operation. The device, running NodeMCU firmware and programmed in LUA, exhibited increased power consumption and failed to reconnect to WiFi despite the OLED display functioning correctly. Users speculated that the LUA file might have been corrupted, leading to the radio module's malfunction. The author confirmed that reprogramming the firmware and the init.lua file resolved the issue. Additionally, the conversation explored power-saving modes available in NodeMCU firmware, highlighting challenges in reducing power consumption while maintaining functionality, particularly in pulse counting applications.
Generated by the language model.

FAQ

TL;DR: ESP8266 NodeMCU sleep currents: 70 mA (NONE), ~20 mA (MODEM), ~15 mA (LIGHT). "NodeMCU firmware provides 4 power saving modes." If Wi‑Fi won’t reconnect and current spikes, compare files and reflash firmware+init.lua. [Elektroda, MichałS, post #18572884]

Why it matters: This FAQ helps ESP8266/ESP‑12 NodeMCU/Lua users fix router reconnect issues and cut battery drain.

Quick Facts

Why won’t my ESP8266 ESP‑12 reconnect to the router after a hang?

A Wi‑Fi subsystem fault or corrupt file state can block association. The MCU may keep running and displaying data while Wi‑Fi fails. Power cycling can leave the fault unchanged. Reflashing NodeMCU firmware and re‑uploading init.lua restored connectivity in practice. That behavior suggests a stuck radio path or damaged Lua file. [Elektroda, MichałS, post #18005745]

How do I recover an ESP8266 that’s stuck with high current and no Wi‑Fi?

Follow this quick reset path:
  1. Power off, wait a few seconds, then power on and confirm the fault persists.
  2. Reflash a stable NodeMCU firmware build to the ESP‑12.
  3. Upload a fresh init.lua, reboot, and verify the station joins your router. This sequence revived a jammed unit. [Elektroda, MichałS, post #18005745]

Can logging to SPIFFS in Lua corrupt files and break networking?

Yes. File writes can corrupt during saves and leave scripts inconsistent. If symptoms reappear, load the stored Lua file and diff it against your original. Some operations block safe writes, so avoid writing during critical tasks. “During certain operations, data cannot be written to the file.” [Elektroda, TvWidget, post #18004926]

My current draw matches the “connecting” phase but it never associates—what does that indicate?

It signals the radio is stuck trying to connect. Users observed current identical to the router‑association phase while Wi‑Fi never completed. OLED and measurements continued, pointing at the Wi‑Fi stack, not the application loop. Reflashing firmware and init.lua resolved it. [Elektroda, MichałS, post #18004814]

What currents should I expect for NodeMCU sleep types on ESP8266?

Typical observed currents: NONE_SLEEP about 70 mA, MODEM_SLEEP about 20 mA, and LIGHT_SLEEP about 15 mA. DEEP_SLEEP gives lowest draw but disables continuous pulse counting. Use these figures as practical targets when budgeting battery life. [Elektroda, MichałS, post #18572884]

Can ESP8266 count pulses while in Light‑sleep?

No. “During Light‑sleep, the CPU is suspended and does not respond to signals and interrupts from peripherals.” Only the RTC keeps running. Continuous pulse counting requires the CPU awake or periodic wake‑ups that service counts. [Elektroda, khoam, post #18572926]

Why is Light‑sleep still drawing tens of milliamps on my NodeMCU board?

Dev boards include regulators, USB‑UART, and LEDs that add quiescent draw. “NodeMCU or Wemos modules are poorly suited to solutions where minimising current consumption matters.” You may need hardware rework or a bare ESP‑12 design for ultra‑low power. [Elektroda, khoam, post #18575192]

Do multiple Lua timers keep ESP8266 awake in Light‑sleep?

Only the RTC timer runs in Light‑sleep. Firmware timers do not execute while the CPU is suspended. If timers continue firing, the device is not actually in Light‑sleep. Audit your sleep configuration and ensure Wi‑Fi sleep type is set correctly. [Elektroda, khoam, post #18575822]

How do I set Wi‑Fi sleep type in NodeMCU Lua?

In your script, set the station sleep type with the Wi‑Fi API. Use wifi.sta.sleeptype with MODEM_SLEEP or LIGHT_SLEEP as needed, then reboot to test current. Apply changes in init.lua to persist them across resets. See the API reference. “wifi.sta.sleepType”

Can I save power and still count pulses without using Deep‑sleep?

Yes, but not with Light‑sleep running continuously. Light‑sleep halts the CPU, so peripheral interrupts for pulse counting do not fire. Use MODEM_SLEEP and optimize code, or add external counting hardware and wake periodically to read it. [Elektroda, khoam, post #18572926]

Are NodeMCU sleep modes equivalent to Espressif’s chip modes?

They map conceptually, but board‑level current differs. Espressif figures apply to the ESP8266 chip only. NodeMCU/Wemos boards consume more in each mode due to onboard components. Budget power using measurements on your exact hardware. [Elektroda, khoam, post #18575192]

How can I baseline current with a minimal Lua test?

Create a simple script that only sets the sleep type and initializes Wi‑Fi. Measure current for each mode to establish expectations on your hardware. This isolates app effects like timers from sleep behavior and clarifies achievable draw. [Elektroda, MichałS, post #18578096]

Do power cycles always clear Wi‑Fi faults on ESP‑12?

No. Users reported that turning power off and on did not restore Wi‑Fi. The application kept running, but the radio remained stuck. A firmware reflash and clean init.lua upload fixed it, confirming a persistent software‑state issue. [Elektroda, MichałS, post #18004814]

What’s a safe way to check for Lua file corruption on ESP8266?

Read the stored Lua file back from flash and compare it byte‑for‑byte with your source. If corruption appears, avoid file writes during operations known to disrupt saving. Re‑upload the corrected file and retest Wi‑Fi. [Elektroda, TvWidget, post #18004926]
Generated by the language model.
ADVERTISEMENT