Simple UDP<--->UART bridge
Posted: Wed Jan 14, 2015 10:10 am
Code: Select all
--!!!!nodemcu_512k_20150106
--Init.lua
PORT=7777 pin=3
gpio.mode(pin, gpio.INPUT)
tmr.alarm(1,5000, 1, function()
if wifi.ap.getip()~=nil then
if gpio.read(pin)==1 then
tmr.stop(1) print("WIFI_UDP_RS232 V1.1 06.01.2015")
else
tmr.stop(1) print("Telnet V1.1") dofile("telnet.lua")
end end end)
uart.setup( 0,9600, 8, 0, 1, 0 )
srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl) tmr.wdclr() uart.write(0,pl) end)
srv:listen(PORT) uart.on("data",0,function(data)srv:send(data)end, 0)
if for 5sec close GPI0 then run telnet.
I like putty.
Code: Select all
--telnet.lua
s=net.createServer(net.TCP,1000)
s:listen(23,function(c)
function s_output(str)
if(c~=nil)
then c:send(str)
end
end
node.output(s_output, 0)
c:on("receive",function(c,l)
node.input(l)
end)
c:on("disconnection",function(c)
node.output(nil)
end)
print("Telnet V1.1")
end)
for test PC HERCULES Utility
for Android my app
https://play.google.com/store/apps/details?id=ru.shipov.termudp