consolidate telnet example
This commit is contained in:
parent
ff3926175c
commit
87351a2d10
|
@ -1,17 +0,0 @@
|
||||||
-- a simple telnet server
|
|
||||||
s=net.createServer(net.TCP,180)
|
|
||||||
s:listen(2323,function(c)
|
|
||||||
function s_output(str)
|
|
||||||
if(c~=nil)
|
|
||||||
then c:send(str)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
|
||||||
c:on("receive",function(c,l)
|
|
||||||
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
|
||||||
end)
|
|
||||||
c:on("disconnection",function(c)
|
|
||||||
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
|
||||||
end)
|
|
||||||
print("Welcome to NodeMcu world.")
|
|
||||||
end)
|
|
|
@ -1,41 +0,0 @@
|
||||||
print("====Wicon, a LUA console over wifi.==========")
|
|
||||||
print("Author: openthings@163.com. copyright&GPL V2.")
|
|
||||||
print("Last modified 2014-11-19. V0.2")
|
|
||||||
print("Wicon Server starting ......")
|
|
||||||
|
|
||||||
function startServer()
|
|
||||||
print("Wifi AP connected. Wicon IP:")
|
|
||||||
print(wifi.sta.getip())
|
|
||||||
sv=net.createServer(net.TCP, 180)
|
|
||||||
sv:listen(8080, function(conn)
|
|
||||||
print("Wifi console connected.")
|
|
||||||
|
|
||||||
function s_output(str)
|
|
||||||
if (conn~=nil) then
|
|
||||||
conn:send(str)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
node.output(s_output,0)
|
|
||||||
|
|
||||||
conn:on("receive", function(conn, pl)
|
|
||||||
node.input(pl)
|
|
||||||
if (conn==nil) then
|
|
||||||
print("conn is nil.")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
conn:on("disconnection",function(conn)
|
|
||||||
node.output(nil)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
print("Wicon Server running at :8080")
|
|
||||||
print("===Now,Using xcon_tcp logon and input LUA.====")
|
|
||||||
end
|
|
||||||
|
|
||||||
tmr.alarm(0, 1000, 1, function()
|
|
||||||
if wifi.sta.getip()=="0.0.0.0" then
|
|
||||||
print("Connect AP, Waiting...")
|
|
||||||
else
|
|
||||||
startServer()
|
|
||||||
tmr.stop()
|
|
||||||
end
|
|
||||||
end)
|
|
|
@ -1,39 +1,35 @@
|
||||||
print("====Wicon, a LUA console over wifi.==========")
|
-- a simple telnet server
|
||||||
print("Author: openthings@163.com. copyright&GPL V2.")
|
|
||||||
print("Last modified 2014-11-19. V0.2")
|
|
||||||
print("Wicon Server starting ......")
|
|
||||||
|
|
||||||
function connected(conn)
|
telnet_srv = net.createServer(net.TCP, 180)
|
||||||
print("Wifi console connected.")
|
telnet_srv:listen(2323, function(socket)
|
||||||
function s_output(str)
|
local fifo = {}
|
||||||
if (conn~=nil) then
|
local fifo_drained = true
|
||||||
conn:send(str)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
node.output(s_output,0)
|
|
||||||
conn:on("receive", function(conn, pl)
|
|
||||||
node.input(pl)
|
|
||||||
end)
|
|
||||||
conn:on("disconnection",function(conn)
|
|
||||||
node.output(nil)
|
|
||||||
end)
|
|
||||||
print("Welcome to NodeMcu world.")
|
|
||||||
end
|
|
||||||
|
|
||||||
function startServer()
|
local function sender(c)
|
||||||
print("Wifi AP connected. Wicon IP:")
|
if #fifo > 0 then
|
||||||
print(wifi.sta.getip())
|
c:send(table.remove(fifo, 1))
|
||||||
sv=net.createServer(net.TCP, 180)
|
else
|
||||||
sv:listen(2323, connected)
|
fifo_drained = true
|
||||||
print("Telnet Server running at :2323")
|
end
|
||||||
print("===Now, logon and input LUA.====")
|
end
|
||||||
end
|
|
||||||
|
|
||||||
tmr.alarm(1, 1000, 1, function()
|
local function s_output(str)
|
||||||
if wifi.sta.getip()=="0.0.0.0" then
|
table.insert(fifo, str)
|
||||||
print("Connect AP, Waiting...")
|
if socket ~= nil and fifo_drained then
|
||||||
else
|
fifo_drained = false
|
||||||
startServer()
|
sender(socket)
|
||||||
tmr.stop(1)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
||||||
|
|
||||||
|
socket:on("receive", function(c, l)
|
||||||
|
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
||||||
|
end)
|
||||||
|
socket:on("disconnection", function(c)
|
||||||
|
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
||||||
|
end)
|
||||||
|
socket:on("sent", sender)
|
||||||
|
|
||||||
|
print("Welcome to NodeMcu world.")
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
-- a simple telnet server
|
|
||||||
|
|
||||||
telnet_srv = net.createServer(net.TCP, 180)
|
|
||||||
telnet_srv:listen(2323, function(socket)
|
|
||||||
local fifo = {}
|
|
||||||
local fifo_drained = true
|
|
||||||
|
|
||||||
local function sender(c)
|
|
||||||
if #fifo > 0 then
|
|
||||||
c:send(table.remove(fifo, 1))
|
|
||||||
else
|
|
||||||
fifo_drained = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function s_output(str)
|
|
||||||
table.insert(fifo, str)
|
|
||||||
if socket ~= nil and fifo_drained then
|
|
||||||
fifo_drained = false
|
|
||||||
sender(socket)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
|
||||||
|
|
||||||
socket:on("receive", function(c, l)
|
|
||||||
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
|
||||||
end)
|
|
||||||
socket:on("disconnection", function(c)
|
|
||||||
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
|
||||||
end)
|
|
||||||
socket:on("sent", sender)
|
|
||||||
|
|
||||||
print("Welcome to NodeMcu world.")
|
|
||||||
end)
|
|
Loading…
Reference in New Issue