From 7b31b0125968a5b2d48b5e2b4ec31c8f8fa5103e Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 14 Mar 2021 15:45:32 +0100 Subject: [PATCH] Added serial debug information --- telnet.lua | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/telnet.lua b/telnet.lua index da97109..d09d96c 100644 --- a/telnet.lua +++ b/telnet.lua @@ -1,21 +1,25 @@ -- Telnet client -local telnetClient=nil -lines = {} +telnetClient=nil +local lines = {} + +-- Helper function +function s_output(str) + uart.write(0, "T:" .. tostring(str)) + if (telnetClient ~= nil) then + if (#lines > 0) then + table.insert(lines, str) + else + table.insert(lines, str) + telnetClient:send("\r") -- Send something, so the queue is read after sending + end + end +end + -- Telnet Server function startTelnetServer() s=net.createServer(net.TCP, 180) s:listen(23,function(c) telnetClient=c - function s_output(str) - if (telnetClient ~= nil) then - if (#lines > 0) then - table.insert(lines, str) - else - table.insert(lines, str) - telnetClient: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) @@ -27,10 +31,15 @@ function startTelnetServer() c:on("sent", function() if (#lines > 0) then local line1=nil - for k,v in pairs(lines) do if (k==1) then line1=v end end + for k,v in pairs(lines) do if (k==1) then + line1=v + end + uart.write(0, "Lines:" .. tostring(v) .. "\r\n") + + end if ( line1 ~= nil ) then table.remove(lines, 1) - print( tostring(line1) ) + uart.write(0, "Telent[" .. tostring(#lines) .. "]" .. tostring(line1) .. "\r\n" ) telnetClient:send(line1) end end @@ -39,6 +48,7 @@ function startTelnetServer() print("- mydofile(\"commands\")") print("- storeConfig()") print("Visite https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en for further commands") + uart.write(0, "New client connected\r\n") end) print("Telnetserver started") end