For my current project i need stable communication between two ESP8266 modules. Basicly i want to send every second or maybe faster measurements data from remote location.
I've already done some coding but its not working as it should be, beacause after a while server module is not receiving any data at all. It worked maybe 5 minutes.
Server side:
-- Konfiguracja stacji
print("Configuring Weather Station AP\n")
wifi.setmode(wifi.STATIONAP)
cfg={}
cfg.ssid="WSServer"
cfg.pwd="12345678"
wifi.ap.config(cfg)
print("Server running: \nSSID:",cfg.ssid,"\npwd:",cfg.pwd)
print("MAC:",wifi.ap.getmac())
print("IP:",wifi.ap.getip())
print("\nConfiguring TCP Server\n")
server = net.createServer(net.TCP)
server:listen(80, function(conn)
conn:on("receive", function(conn, receivedData)
print("received: " .. receivedData)
message = "Hi, I read You."
conn:send(message); message = nil
end)
conn:on("sent", function(conn)
collectgarbage()
end)
end)
print("\nDone!\n")
Client side:
-- CODE FOR CLIENT ESP
wifi.sta.disconnect()
wifi.setmode(wifi.STATION)
SSID="WSServer"
PSW="12345678"
wifi.sta.config(SSID,PSW) -- connecting to server
wifi.sta.connect()
print("Waiting for connection")
tmr.alarm(1,1000,1,function()
if(wifi.sta.getip()~=nil) then
tmr.stop(1)
print("Connected!")
print("SSID:",SSID);
print("IP:",wifi.sta.getip())
print("MAC:",wifi.sta.getmac())
sk=net.createConnection(net.TCP, 0)
sk:connect(80,"192.168.4.1")
else
print("...")
end
end)
function send(data)
sk:send(data)
end
Any thoughts are welcome.