As the title says... Chat on...

User avatar
By azekie
#3467 Hi,

Does any one has a working UDP server example in LUA? I tried the following code, it seems that server starts but UDP messages are not received! note that I'm sending UDP messages to ESP8266 from my Android phone using UDP Sender App which works fine with other UDP servers.

Code: Select allpin=8
port=5000
print("IP:"..wifi.sta.getip()..", Port:"..port)
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.LOW)
srv=net.createServer(net.UDP)
srv:listen(port,function(conn)
conn:on("receive", function(conn, pl)
   print("Command Reveived")
   if pl=="on" then gpio.write(pin, gpio.HIGH) else gpio.write(pin, gpio.LOW) end
   end)
end)
Last edited by azekie on Mon Dec 01, 2014 8:25 am, edited 2 times in total.
User avatar
By azekie
#3713 Thanks, following code is working now:

Code: Select allpin=8
port=5000
print("IP:"..wifi.sta.getip()..", Port:"..port)
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.LOW)
srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl)
   print("Command Reveived")
   if pl=="on" then gpio.write(pin, gpio.HIGH) else gpio.write(pin, gpio.LOW) end
   end)
srv:listen(port)