From ba6193ff5b10d350938248c47752ed137f6c6afd Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 21 Feb 2020 20:21:54 +0100 Subject: [PATCH] Telnet included --- main.lua | 9 ++++++--- telnet.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 telnet.lua diff --git a/main.lua b/main.lua index 3a03567..8c85f37 100644 --- a/main.lua +++ b/main.lua @@ -147,7 +147,7 @@ function normalOperation() print('IP: ',wifi.sta.getip()) -- Here the WLAN is found, and something is done print("Solving dependencies") - local dependModules = { "timecore" , "wordclock" } + local dependModules = { "timecore" , "wordclock", "telnet" } for _,mod in pairs(dependModules) do print("Loading " .. mod) mydofile(mod) @@ -157,8 +157,11 @@ function normalOperation() syncTimeFromInternet() end) tmr.alarm(3, 2000, 0 ,function() - -- FIXME start telent server - print("Load telnet") + if (startTelnetServer ~= nil) then + startTelnetServer() + else + print("NO Telent found") + end end) displayTime() -- Start the time Thread diff --git a/telnet.lua b/telnet.lua new file mode 100644 index 0000000..ab55c21 --- /dev/null +++ b/telnet.lua @@ -0,0 +1,35 @@ +-- Telnet Server +function startTelnetServer() + s=net.createServer(net.TCP, 180) + s:listen(23,function(c) + global_c=c + printlines = {} + function s_output(str) + if(global_c~=nil) then + if #printlines > 0 then + printlines[ #printlines + 1] = str + else + printlines[ #printlines + 1] = str + global_c:send("\r") -- Send something, so the queue is read after sending + end + end + end + node.output(s_output, 0) + c:on("receive",function(c,l) + node.input(l) + end) + c:on("disconnection",function(c) + node.output(nil) + global_c=nil + end) + c:on("sent", function() + if #printlines > 0 then + global_c:send(table.remove(printlines, 1)) + end + end) + print("Welcome to the Wordclock.") + print("Visite https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en for further commands") + end) + print("Telnetserver is up") +end +