How to restore infinite loop nodemcu
I made a mistake loading init.lua with infinite loop on my nodemcu / ESP8266 board.
The board then continues to reboot without any other instruction.
i = 10 timerId = 0 timerDelay = 30000 -- Milisec pin = 5 gpio.mode(pin,gpio.INPUT) repeat( print(gpio.read(pin)) i = i + 1 end) until i < 5
source to share
I am using ESPlorer (Java Application) http://esp8266.ru/esplorer/#download
While I'm cheating, I just have my init.lua
file named init1.lua
, if ESP doesn't reload it you just click the button init1.lua
that is displayed on the right (after you use Reload to display the contents of the filesystem)
Nice and easy, when you do that, you can right click on the file to rename it back to init.lua
.
source to share
--This file is init.lua
local IDLE_AT_STARTUP_MS = 10000;
tmr.alarm(1,IDLE_AT_STARTUP_MS,0,function()
dofile("program.lua")--Write your program name in dofile
end)
I use this strategy to prevent an infinite loop on startup when an error occurs. Save this file as init.lua and write your programs in program.lua
source to share
There is no elegant way to recover.
The best thing to do is build a way to prevent your code from speaking out in an emergency. For example, as TerryE suggests, set a one-shot timer using timer.alarm
in init.lua
to trigger your main code with a long enough delay that you can call timer.stop
in case you don't want to load into your main code.
source to share