nodemcu刷如不当lua代码会导致再也刷不进lua脚本
1.lua死循环
LED_PIN = 0
US_TO_MS = 1000
gpio.mode(LED_PIN, gpio.OUTPUT)
ledstate = 0
--while true do --死循环无法刷机,还有使用串口也是一样,所以要注意了
-- gpio.write(LED_PIN, gpio.HIGH)
--tmr.delay(500 * US_TO_MS)
-- gpio.write(LED_PIN, gpio.LOW)
--tmr.delay(500 * US_TO_MS)
--end
gpio.write(LED_PIN, gpio.HIGH)
tmr.alarm(0,1000,1,function()
if ledstate == 0 then
ledstate = 1
gpio.write(LED_PIN, gpio.HIGH)
else
ledstate = 0
gpio.write(LED_PIN, gpio.LOW)
end
end)
function uartsend(param)
print("echo:"..param)
end
2.启用串口,没有退出回调函数
--uart.alt(0)
-- configure for 9600, 8N1, with echo
--uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1)
uart.setup(0,9600,8,0,1)
-- when '\r' is received.
uart.on("data", "\r",
function(data)
print("receive from uart:", data)
uart.write(0, "receive from uart:"..data)
if data=="quit\r" then
uart.on("data") -- unregister callback function
end
end, 0)