Added serial debug information
This commit is contained in:
parent
5fafff7abc
commit
7b31b01259
28
telnet.lua
28
telnet.lua
@ -1,12 +1,10 @@
|
|||||||
-- Telnet client
|
-- Telnet client
|
||||||
local telnetClient=nil
|
telnetClient=nil
|
||||||
lines = {}
|
local lines = {}
|
||||||
-- Telnet Server
|
|
||||||
function startTelnetServer()
|
-- Helper function
|
||||||
s=net.createServer(net.TCP, 180)
|
|
||||||
s:listen(23,function(c)
|
|
||||||
telnetClient=c
|
|
||||||
function s_output(str)
|
function s_output(str)
|
||||||
|
uart.write(0, "T:" .. tostring(str))
|
||||||
if (telnetClient ~= nil) then
|
if (telnetClient ~= nil) then
|
||||||
if (#lines > 0) then
|
if (#lines > 0) then
|
||||||
table.insert(lines, str)
|
table.insert(lines, str)
|
||||||
@ -16,6 +14,12 @@ function startTelnetServer()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Telnet Server
|
||||||
|
function startTelnetServer()
|
||||||
|
s=net.createServer(net.TCP, 180)
|
||||||
|
s:listen(23,function(c)
|
||||||
|
telnetClient=c
|
||||||
node.output(s_output, 0)
|
node.output(s_output, 0)
|
||||||
c:on("receive",function(c,l)
|
c:on("receive",function(c,l)
|
||||||
node.input(l)
|
node.input(l)
|
||||||
@ -27,10 +31,15 @@ function startTelnetServer()
|
|||||||
c:on("sent", function()
|
c:on("sent", function()
|
||||||
if (#lines > 0) then
|
if (#lines > 0) then
|
||||||
local line1=nil
|
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
|
if ( line1 ~= nil ) then
|
||||||
table.remove(lines, 1)
|
table.remove(lines, 1)
|
||||||
print( tostring(line1) )
|
uart.write(0, "Telent[" .. tostring(#lines) .. "]" .. tostring(line1) .. "\r\n" )
|
||||||
telnetClient:send(line1)
|
telnetClient:send(line1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -39,6 +48,7 @@ function startTelnetServer()
|
|||||||
print("- mydofile(\"commands\")")
|
print("- mydofile(\"commands\")")
|
||||||
print("- storeConfig()")
|
print("- storeConfig()")
|
||||||
print("Visite https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en for further commands")
|
print("Visite https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en for further commands")
|
||||||
|
uart.write(0, "New client connected\r\n")
|
||||||
end)
|
end)
|
||||||
print("Telnetserver started")
|
print("Telnetserver started")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user