Create SERVER|CLIENT on AP for every STATION port?
Create STATIONAP on every node?
Any ideas?
Explore... Chat... Share...
dnc40085 wrote:If they are all on the same AP ... you can use net.createserver(receive data) and net.createconnection(transmit data) for communication between stations.
port=5000
gpio.mode(3,gpio.INPUT)
sk=net.createConnection(net.UDP,0)
sk:on("receive",function(sk,pl) print('INPT:',pl) end)
sk:connect(port,"192.168.4.66")
tmr.alarm(0,5000,1,function()
if gpio.read(3)==1 then
pl="on"
else
pl="off"
end
sk:send(pl)
print('OUTPUT:',pl)
end)srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl)
print(' INPUT:', pl)
end)
srv:listen(port)print("init will begin in 3 seconds")
function client()
Client9001=net.createConnection(net.TCP, 0)
Client9001:on("connection", function()
print("connected")
Client9001:send("HELLO SERVER!")
end)
Client9001:on("receive", function(sck, c)
tmr.stop(3)
print(c)
if string.find(c, "Hello Client") then
Client9001:send("I'm going to disconnect now")
end
if string.find(c, "disconnect_ack") then
Client9001:close()
end
end)
Client9001:on("disconnection", function()
print("disconnected")
Client9001=nil
end)
Client9001:connect(9000,"10.0.0.200")
end
tmr.alarm(0, 3000, 0, function()
print("init.lua START")
wifi.setmode(1)
wifi.sta.config ("MYSSID","MYPASSWORD")
tmr.alarm(0, 10, 1, function()
local Conn_status=wifi.sta.status()
if (Conn_status==5) then
cfg={ip="10.0.0.100", netmask="255.255.255.0", gateway="10.0.0.1"}
wifi.sta.setip(cfg)
tmr.stop(0)
print("CONNECTED TO AP")
print("Starting tcp server on port 9001")
server = net.createServer(net.TCP,15)
server:listen(8000, function(conn)
conn:on("receive",function(conn,data)
print(data)
if string.find(data, "HELLO SERVER") then
conn:send("Hello Client")
end
if string.find(data, "I'm going to disconnect now") then
conn:send("disconnect_ack")
end
end)
conn:on("disconnection", function() print("disconnected"); end)
end)
print("Server started")
end
end)
print("init.lua END")
end)
if false then
client()
server:close()
end
print("init will begin in 3 seconds")
function client()
Client9001=net.createConnection(net.TCP, 0)
Client9001:on("connection", function()
print("connected")
Client9001:send("HELLO SERVER!")
end)
Client9001:on("receive", function(sck, c)
tmr.stop(3)
print(c)
if string.find(c, "Hello Client") then
Client9001:send("I'm going to disconnect now")
end
if string.find(c, "disconnect_ack") then
Client9001:close()
end
end)
Client9001:on("disconnection", function()
print("disconnected")
Client9001=nil
end)
Client9001:connect(8000,"10.0.0.100")
end
tmr.alarm(0, 3000, 0, function()
print("init.lua START")
wifi.setmode(1)
wifi.sta.config ("MYSSID","MYPASSWORD")
tmr.alarm(0, 10, 1, function()
local Conn_status=wifi.sta.status()
if (Conn_status==5) then
cfg={ip="10.0.0.200", netmask="255.255.255.0", gateway="10.0.0.1"}
wifi.sta.setip(cfg)
print("CONNECTED TO AP")
print("Starting tcp server on port 9001")
server = net.createServer(net.TCP,15)
server:listen(9000, function(conn)
conn:on("receive",function(conn,data)
print(data)
if string.find(data, "HELLO SERVER") then
conn:send("Hello Client")
end
if string.find(data, "I'm going to disconnect now") then
conn:send("disconnect_ack")
end
end)
conn:on("disconnection", function() print("disconnected"); end)
end)
tmr.stop(0)
print("Server started")
end
end)
print("init.lua END")
end)
if false then
tmr.alarm(0, 5000, 1, client)
client()
server:close()
end
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]