update a new telnet example
This commit is contained in:
parent
95e71987e4
commit
002d3c91a5
10
README.md
10
README.md
|
@ -93,6 +93,7 @@ braudrate:9600
|
||||||
print(payload)
|
print(payload)
|
||||||
conn:send("<h1> Hello, NodeMcu.</h1>")
|
conn:send("<h1> Hello, NodeMcu.</h1>")
|
||||||
end)
|
end)
|
||||||
|
conn:on("sent",function(conn) conn:close() end)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -139,12 +140,11 @@ braudrate:9600
|
||||||
####With below code, you can telnet to your esp8266 now
|
####With below code, you can telnet to your esp8266 now
|
||||||
```lua
|
```lua
|
||||||
-- a simple telnet server
|
-- a simple telnet server
|
||||||
s=net.createServer(net.TCP)
|
s=net.createServer(net.TCP,180)
|
||||||
s:listen(2323,function(c)
|
s:listen(2323,function(c)
|
||||||
con_std = c
|
|
||||||
function s_output(str)
|
function s_output(str)
|
||||||
if(con_std~=nil)
|
if(c~=nil)
|
||||||
then con_std:send(str)
|
then c:send(str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
||||||
|
@ -152,9 +152,9 @@ braudrate:9600
|
||||||
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
||||||
end)
|
end)
|
||||||
c:on("disconnection",function(c)
|
c:on("disconnection",function(c)
|
||||||
con_std = nil
|
|
||||||
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
||||||
end)
|
end)
|
||||||
|
print("Welcome to NodeMcu world.")
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
#Check this out
|
#Check this out
|
||||||
|
|
|
@ -3,32 +3,30 @@ print("Author: openthings@163.com. copyright&GPL V2.")
|
||||||
print("Last modified 2014-11-19. V0.2")
|
print("Last modified 2014-11-19. V0.2")
|
||||||
print("Wicon Server starting ......")
|
print("Wicon Server starting ......")
|
||||||
|
|
||||||
|
function connected(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)
|
||||||
|
end)
|
||||||
|
conn:on("disconnection",function(conn)
|
||||||
|
node.output(nil)
|
||||||
|
end)
|
||||||
|
print("Welcome to NodeMcu world.")
|
||||||
|
end
|
||||||
|
|
||||||
function startServer()
|
function startServer()
|
||||||
print("Wifi AP connected. Wicon IP:")
|
print("Wifi AP connected. Wicon IP:")
|
||||||
print(wifi.sta.getip())
|
print(wifi.sta.getip())
|
||||||
sv=net.createServer(net.TCP, 180)
|
sv=net.createServer(net.TCP, 180)
|
||||||
sv:listen(8080, function(conn)
|
sv:listen(2323, connected)
|
||||||
print("Wifi console connected.")
|
print("Telnet Server running at :2323")
|
||||||
|
print("===Now, logon and input LUA.====")
|
||||||
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
|
end
|
||||||
|
|
||||||
tmr.alarm(1000, 1, function()
|
tmr.alarm(1000, 1, function()
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
-- 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)
|
Loading…
Reference in New Issue