UDP广播 MAC地址
1 enduser_setup.start() 2 ListenPort = 8080 3 wifi.setmode(wifi.STATIONAP) 4 5 wifi.sta.autoconnect(1) 6 7 clientid = wifi.sta.getmac() 8 print(clientid) 9 UdpSocket = net.createUDPSocket() 10 UdpSocket:listen(ListenPort) 11 UdpSocket:on("receive", function(s, data, port, ip) 12 print(string.format("received '%s' from %s:%d", data, ip, port)) 13 s:send(port, ip, "echo: " .. clientid) 14 end) 15 16 printip = 0 17 wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED, function(T) 18 printip = 0 19 end) 20 wifi.eventmon.register(wifi.eventmon.STA_GOT_IP, function(T) 21 if printip == 0 then 22 print("+IP "..T.IP) 23 RSSI=wifi.sta.getrssi()--信号 24 print("RSSI is", RSSI) 25 end 26 printip = 1 27 end)
打开UDP访问192.168.8.197 4000端口
随意发送
收到设备MAC地址
能在此遇见是我们的缘分,我愿意帮助你,相信你一定可以取得成功!
扫码关注微信公众号 “小樊Study”获取更多
QQ群
淘宝店铺