I am using NodeMCU (with ESP8266-E) with an upgraded firmware. All basic commands work perfectly but there is one problem.
I wanted to create an independent access point, which could have a behaviour like a UDP server. That means without direct connection to any other access points. A simple UDP server like soft AP.
I followed these steps:
- I have uploaded a new firmware to NodeMCU.
- I have downloaded ESPlorer for better work with NodeMCU.
- I have uploaded the source code below.
- I have connected to the NodeMCU access point on my desktop.
- I have sent some strings to the NodeMCU using a Java UDP client program.
- I have looked at the messages on ESPlorer.
- NodeMCU has not received any such strings.
--
print("ESP8266 Server")
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid="test",pwd="12345678"});
print("Server IP Address:",wifi.ap.getip())
-- 30s timeout for an inactive client
srv = net.createServer(net.UDP, 30)
-- server listens on 5000, if data received, print data to console
srv:listen(5000, function(sk)
sk:on("receive", function(sck, data)
print("received: " .. data)
end)
sk:on("connection", function(s)
print("connection established")
end)
end)
When I tried to send a message using a Java application, there was no change in ESPlorer. Not even when I tried to send a message using the Hercules program (great program for TCP, UDP communication).
I guess that maybe it will be the wrong IP address. I am using the IP address of the AP and not the IP address of the station.
In other words I am using this address: wifi.ap.getip()
and not this address wifi.sta.getip()
for connections to the UDP server. But sta.getip()
returns a nil object. Really I don't know.
I will be glad for any advice.
Thank you very much.