Skip to content

Commit ca4c537

Browse files
author
vsky
committed
Fix to telnet lua example and ftpserver lua module in consequence of PR nodemcu#2603
1 parent 5514475 commit ca4c537

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lua_examples/telnet/telnet.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ local function telnet_listener(socket)
5555
-- debug("entering sendLine")
5656
if not s then return end
5757

58-
if fifo2l + fifo1l == 0 then -- both FIFOs empty, so clear down s
58+
if fifo2l + fifo1l == 0 then -- both FIFOs empty, so clear down s
5959
s = nil
6060
-- debug("Q cleared")
6161
return
@@ -67,7 +67,7 @@ local function telnet_listener(socket)
6767
insert(fifo2,concat(fifo1))
6868
-- debug("flushing %u bytes / %u recs of FIFO1 into FIFO2[%u]", fifo1l, #fifo1, #fifo2)
6969
fifo2l, fifo1, fifo1l = fifo2l + fifo1l, {}, 0
70-
end
70+
end
7171

7272
-- send out first 4 FIFO2 recs (or all if #fifo2<5)
7373
local rec = remove(fifo2,1) .. (remove(fifo2,1) or '') ..
@@ -134,6 +134,7 @@ local function telnet_listener(socket)
134134
socket:on("disconnection", disconnect)
135135
socket:on("sent", sendLine)
136136
node.output(queueLine, 0)
137+
print(("Welcome to NodeMCU world (%d mem free, %s)"):format(node.heap(), wifi.sta.getip()))
137138
end
138139

139140
local listenerSocket
@@ -143,11 +144,12 @@ return {
143144
wifi.setmode(wifi.STATION, false)
144145
wifi.sta.config { ssid = ssid, pwd = pwd, save = false }
145146
end
146-
tmr.alarm(0, 500, tmr.ALARM_AUTO, function()
147+
local t = tmr.create()
148+
t:alarm(500, tmr.ALARM_AUTO, function()
147149
if (wifi.sta.status() == wifi.STA_GOTIP) then
148-
tmr.unregister(0)
149-
print("Welcome to NodeMCU world", node.heap(), wifi.sta.getip())
150-
net.createServer(net.TCP, 180):listen(port or 2323, telnet_listener)
150+
t:unregister()
151+
t=nil
152+
net.createServer(net.TCP, 180):listen(port or 23, telnet_listener)
151153
else
152154
uwrite(0,".")
153155
end

lua_modules/ftp/ftpserver.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ function FTP.open(user, pass, ssid, pwd, dbgFlag) -- upval: FTP (, wifi, tmr, pr
5959
wifi.setmode(wifi.STATION, false)
6060
wifi.sta.config { ssid = ssid, pwd = pwd, save = false }
6161
end
62-
tmr.alarm(0, 500, tmr.ALARM_AUTO, function()
62+
local t = tmr.create()
63+
t:alarm(500, tmr.ALARM_AUTO, function()
6364
if (wifi.sta.status() == wifi.STA_GOTIP) then
64-
tmr.unregister(0)
65+
t:unregister()
66+
t=nil
6567
print("Welcome to NodeMCU world", node.heap(), wifi.sta.getip())
6668
return FTP.createServer(user, pass, dbgFlag)
6769
else

0 commit comments

Comments
 (0)