Skip to content

Commit

Permalink
Fix to telnet lua example and ftpserver lua module in consequence of PR
Browse files Browse the repository at this point in the history
  • Loading branch information
vsky committed Feb 10, 2019
1 parent 5514475 commit e80425c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions lua_examples/telnet/telnet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ local function telnet_listener(socket)
-- debug("entering sendLine")
if not s then return end

if fifo2l + fifo1l == 0 then -- both FIFOs empty, so clear down s
if fifo2l + fifo1l == 0 then -- both FIFOs empty, so clear down s
s = nil
-- debug("Q cleared")
return
Expand Down Expand Up @@ -125,15 +125,16 @@ local function telnet_listener(socket)
node.input(line)
end

local function disconnect(s)
local function discontect(s)
fifo1, fifo1l, fifo2, fifo2l, s = {}, 0, {}, 0, nil
node.output(nil)
end

socket:on("receive", receiveLine)
socket:on("disconnection", disconnect)
socket:on("disconnection", discontect)
socket:on("sent", sendLine)
node.output(queueLine, 0)
print(("Welcome to NodeMCU world (%d mem free, %s)"):format(node.heap(), wifi.sta.getip()))
end

local listenerSocket
Expand All @@ -143,11 +144,11 @@ return {
wifi.setmode(wifi.STATION, false)
wifi.sta.config { ssid = ssid, pwd = pwd, save = false }
end
tmr.alarm(0, 500, tmr.ALARM_AUTO, function()
local tmr_wait = tmr.create()
tmr_wait:alarm(500, tmr.ALARM_AUTO, function()
if (wifi.sta.status() == wifi.STA_GOTIP) then
tmr.unregister(0)
print("Welcome to NodeMCU world", node.heap(), wifi.sta.getip())
net.createServer(net.TCP, 180):listen(port or 2323, telnet_listener)
tmr_wait:unregister()
net.createServer(net.TCP, 180):listen(port or 23, telnet_listener)
else
uwrite(0,".")
end
Expand Down
5 changes: 3 additions & 2 deletions lua_modules/ftp/ftpserver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ function FTP.open(user, pass, ssid, pwd, dbgFlag) -- upval: FTP (, wifi, tmr, pr
wifi.setmode(wifi.STATION, false)
wifi.sta.config { ssid = ssid, pwd = pwd, save = false }
end
tmr.alarm(0, 500, tmr.ALARM_AUTO, function()
local tmr_wait = tmr.create()
tmr_wait:alarm(500, tmr.ALARM_AUTO, function()
if (wifi.sta.status() == wifi.STA_GOTIP) then
tmr.unregister(0)
tmr_wait:unregister()
print("Welcome to NodeMCU world", node.heap(), wifi.sta.getip())
return FTP.createServer(user, pass, dbgFlag)
else
Expand Down

0 comments on commit e80425c

Please sign in to comment.