Hi,
for my current project i need stable communication between two esp8266 modules. basically i want to send & receive every second or maybe faster measurements data between to station & remote location.
i have already some codeing but its not working as it should be, client send data to server, but how to send data from server to one or more client. like one super node and more than one nodes,
please Help me.....
ESPlorer Lua... code
Client
--------- SETTINGS ---------
SSID="WS"
PWD="12345678"
----------------------------
---------- VARIABLES --------
conn_flag = 0
--------- FUNCTIONS --------
function connect_wifi(ssid,pwd)
if (conn_flag == 0) then
print("Waiting for connection...")
print("#1")
else
print("Reconnecting...")
print("#1")
end
timer1=0
wifi.setmode(wifi.STATION)
wifi.sta.config(ssid,pwd)
wifi.sta.connect()
tmr.alarm(1,1000,1,function()
if(wifi.sta.getip()~=nil) then
tmr.stop(1)
print("Connected to:", SSID)
print("IP:",wifi.sta.getip())
print("MAC:",wifi.sta.getmac())
conn_flag = 1
elseif(timer1==10) then
print("Unable to connect to:",SSID)
tmr.stop(1)
end
end)
end
function connect_tcp()
tmr.alarm(2,1000,1,function()
sk = net.createConnection(net.TCP, 0)
sk:on("receive", function(sk, receivedData)
print("received: " .. receivedData)
end)
sk:on("connection", function(sk)
print("Connected!")
print("#2")
tmr.stop(2)
end )
sk:on("disconnection", function(sk)
print("Disconnected!")
print("#0")
connect_wifi(SSID,PWD)
connect_tcp()
end )
sk:connect(80, "192.168.4.1") -- server ESP IP
collectgarbage()
end)
end
function send(data)
sk:send(data)
end
----------------------------
connect_wifi(SSID,PWD)
connect_tcp()
Hi, for my current project i need stable communication between two esp8266 modules. basically i want to send & receive every second or maybe faster measurements data between to station & remote location. i have already some codeing but its not working as it should be, client send data to server, but how to send data from server to one or more client. like one super node and more than one nodes,
please Help me..... ESPlorer Lua... code
Client
server