如何恢复NodeMCU无限循环。

我在我的 nodemcu/ESP8266 开发板上加载 init.lua 时出现了无限循环的错误。

然后开发板一直重启并未执行其他任何指令。

i = 10
timerId = 0
timerDelay = 30000 -- 毫秒
pin = 5
gpio.mode(pin,gpio.INPUT)
repeat(
    print(gpio.read(pin))
    i = i + 1
    end)
until i < 5
点赞
用户2696938
用户2696938

我尝试刷写板子

python esptool.py -p /dev/tty.wchusbserial1450 run

python esptool.py -p /dev/tty.wchusbserial1450 write_flash 0x0000 ../nodemcu_latest.bin

然后修复了我的代码,重新加载它,现在正常工作。

2015-07-11 03:48:20
用户1816847
用户1816847

将下面翻译成中文并且保留原本的 markdown 格式,

There's isn't an elegant way to recover.

The best thing to do is build in a way to get prevent your code from stating in an emergency. For example, as TerryE suggests, set a one-shot timer using `timer.alarm` in `init.lua` to call your main code with a long enough delay that you can call `timer.stop` in the case that you don't want to boot into your main code.
- 没有优雅的方式来进行恢复。

- 最好的方法是构建一种防止您的代码在紧急情况下启动的方式。例如,正如 TerryE 所建议的那样,在 `init.lua` 中使用 `timer.alarm` 设置一个一次性定时器来调用您的主代码,并延迟足够长的时间,以便在您不想引导到主代码的情况下调用 `timer.stop`。
2015-10-04 19:16:57
用户1721055
用户1721055

我所做的是使用 ESPlorer(Java 应用程序)http://esp8266.ru/esplorer/#download

当我在折腾时,我只需将我的 init.lua 文件称为 init1.lua,如果 ESP 重新启动,没有问题,您只需单击显示在右侧的 init1.lua 按钮(在使用“重新加载”按钮显示文件系统内容后)

非常简单,当你完成后,你可以右键单击文件将其重命名为 init.lua

2015-12-01 04:22:55
用户4246926
用户4246926

文件:init.lua

在启动时使用此策略以防止出现无限循环的错误。将此文件保存为init.lua并将您的程序写入program.lua中。

--此文件是init.lua
local IDLE_AT_STARTUP_MS = 10000;

tmr.alarm(1,IDLE_AT_STARTUP_MS,0,function()
    dofile("program.lua")--在dofile中写入您的程序名称
end)
2016-03-21 20:41:10
用户8525531
用户8525531

我遇到了同样的问题,陷入了 while 循环。

对我来说,刷了不同的固件就解决了问题。

2017-09-21 04:51:46
用户2251364
用户2251364

这个答案基本上和 researcher01 的答案 相同,但使用了 OO API timers,因为上面使用的API在2019年被删除。

--这个文件是 init.lua
local IDLE_AT_STARTUP_MS = 10000;

tmr.create():alarm(IDLE_AT_STARTUP_MS, tmr.ALARM_SINGLE,function()
    dofile("program.lua")--在 dofile 中写入您的程序名称
end)
2021-01-27 23:43:42