【发布时间】:2017-04-16 18:34:47
【问题描述】:
我正在使用来自 nodemcu repo 的这个示例:
uart.setup(0,9600,8,0,1,0)
sv=net.createServer(net.TCP, 60)
global_c = nil
sv:listen(9999, function(c)
if global_c~=nil then
global_c:close()
end
global_c=c
c:on("receive",function(sck,pl) uart.write(0,pl) end)
end)
uart.on("data",4, function(data)
if global_c~=nil then
global_c:send(data)
end
end, 0)
但是,由于我使用的是 uart 模块,我无法再通过 LuaLoader 与我的芯片通信,也无法上传更新的init.lua 文件。相反,我必须将芯片置于闪存上传模式,然后刷新初始 nodemcu 固件,然后更新我的 init.lua。步骤太多。
如何保留通过 LuaLoader 进行通信的能力?我试过这样的事情:
uart.on('data', '\n', handleUartResponse, 0)
...
...
function handleUartResponse(response)
if response == 'flash\n' then
g_flash = true
toggleOutput(true)
uart.write(0, 'flash mode')
elseif response == 'endflash\n' then
g_flash = false
uart.write(0, 'normal mode')
toggleOutput(false)
elseif g_flash then
node.input(response)
else
if g_conn ~= nil then
g_conn:send(response, function(sock)
closeConnection(sock)
g_conn = nil
end)
end
end
end
function toggleOutput(turnOn)
if turnOn then
node.output(nil, 1)
else
node.output(silent, 0)
end
end
它在另一个串行终端中打印flash mode 和normal mode,但它在 LuaLoader 中不起作用。我认为问题在于 uart 设置,可能不应该是\n,但其他情况,我不知道是什么。
【问题讨论】: