sumotoy / RA8875

A library for RAiO RA8875 display driver for Teensy3.x or LC/Arduino's/Energia/Spark
GNU General Public License v3.0
79 stars 55 forks source link

communication between two esp8266 #107

Closed dkumariet closed 8 years ago

dkumariet commented 8 years ago

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()

server

print("configuring ap")

wifi.setmode(wifi.STATIONAP)
cfg={}
cfg.ssid="WS"
cfg.pwd="12345678"
wifi.ap.config(cfg)

print("config TCP server")
server = net.createServer(net.TCP,28800)
server:listen(80, function(conn)
     conn:on("receive",function(conn,data)
          print(data)

     end)
     conn:on("sent",function(conn)
          collectgarbage()
     end)
          conn:on("connection",function(conn)
          print("Connected")
     end)
end)
print("done")
sumotoy commented 8 years ago

Sorry, I don't know LUA. Also this is not related to RA8875!!! You should ask in a LUA esp8266 forum, not here!