diff --git a/nodemcu/telnet.lua b/nodemcu/telnet.lua index 068b79f..2283b79 100644 --- a/nodemcu/telnet.lua +++ b/nodemcu/telnet.lua @@ -1,19 +1,19 @@ return function(port) - function connected(conn) - negotiate = string.char(255, 253, 34, 255, 250, 34, 1, 0, 255, 240, 255, 251, 1) - conn:send(negotiate) - conn:on("receive", function(conn, pl) - conn:send('.') - uart.write(0, pl) - end) - end - - function startTelnet() - print("Starting Telnet server") - sv = net.createServer(net.TCP, 180) - sv:listen(23, connected) - print("Telnet server now started") - end - startTelnet() --- uart.setup(0, 9600, 8, 0, 1, 0) + -- a simple telnet server + s=net.createServer(net.TCP,180) + s:listen(port,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) end