-->
Page 2 of 2

Re: Peer to Peer communication between ESP8266

PostPosted: Wed Nov 04, 2015 11:06 am
by Gabi Mihai
Try this
It works for me between 2 esp-07


-- a udp client asta transmite dar nu receptioneaza
wifi.sleeptype(wifi.MODEM_SLEEP)
wifi.setphymode(wifi.PHYMODE_N)
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid="CLIENT",pwd="xxxxxxxx"});
wifi.ap.setip({ip="172.10.10.1",nm="255.255.255.0",gw="172.10.10.1"});
wifi.sta.config("SERVER","xxxxxxxx");
wifi.sta.setip({ip="10.10.10.2",nm="255.255.255.0", gw="10.10.10.1"});
tmr.alarm(0, 500, 1, function()
if wifi.sta.status() ~= 5 then
print("IP unavaiable, Waiting...");
else
print("ESP8266 mode is: " .. wifi.getmode());
print("The module MAC address is: " .. wifi.ap.getmac());
print("SERVER AP IP is "..wifi.ap.getip());
print("SERVER STA IP is "..wifi.sta.getip());
print("SERVER STA CONNECTED");
tmr.stop(0);
end
end)
tmr.alarm(1, 5000, 1, function() node.restore() end)
function client()
uart.setup( 0,115200, 8, 0, 1, 1 )
srv=net.createServer(net.UDP,0)
srv:on("receive", function(srv, pl) tmr.wdclr() uart.write(0,pl) end)
srv:listen(1000) uart.on("data",0,function(data)srv:send(data)end, 0)

c=net.createConnection(net.UDP)
c:connect(1000,"10.10.10.1")
uart.on("data",0,function(data) c:send(data)end, 0)
end
client()





--udp server asta receptioneaza dar nu transmite
wifi.sleeptype(wifi.MODEM_SLEEP)
wifi.setphymode(wifi.PHYMODE_N)
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid="SERVER",pwd="xxxxxxxx"});
wifi.ap.setip({ip="10.10.10.1",nm="255.255.255.0",gw="10.10.10.1"});
wifi.sta.config("CLIENT","xxxxxxxx");
wifi.sta.setip({ip="172.10.10.2",nm="255.255.255.0", gw="172.10.10.1"});
tmr.alarm(0, 1000, 1, function()
if wifi.sta.status() ~= 5 then
print("IP unavaiable, Waiting...");
else
print("ESP8266 mode is: " .. wifi.getmode());
print("The module MAC address is: " .. wifi.ap.getmac());
print("SERVER AP IP is "..wifi.ap.getip());
print("SERVER STA IP is "..wifi.sta.getip());
print("SERVER STA CONNECTED");
tmr.stop(0);
end
end)
tmr.alarm(1, 5000, 1, function() node.restore() end)
function server()
uart.setup( 0,115200, 8, 0, 1, 1 )
srv=net.createServer(net.UDP,0)
srv:on("receive", function(srv, pl) tmr.wdclr() uart.write(0,pl) end)
srv:listen(1000) uart.on("data",0,function(data)srv:send(data)end, 0)

c=net.createConnection(net.UDP)
c:connect(1000,"172.10.10.1")
uart.on("data",0,function(data) c:send(data)end, 0)
end
server()


The firmware is one custom build nodemcu-dev-29-modules-2015-11-04-13-35-22-float

Re: Peer to Peer communication between ESP8266

PostPosted: Wed Nov 04, 2015 3:25 pm
by Gabi Mihai
Sorry
I have 2 ESP12

Re: Peer to Peer communication between ESP8266

PostPosted: Sat Jan 16, 2016 5:28 pm
by Trickuncle
@ Gabi Mihai - Thanks! I just tried your code and it seems to work fine on Adafruit ESP8266 Huzzah boards.

Data in uart here, out uart there and vice versa.

Re: Peer to Peer communication between ESP8266

PostPosted: Fri Jan 29, 2016 1:43 am
by Tmt
Can any one help me in this.
How many Modules i can connect with each other in network?