【IOT】小项目1

    xiaoxiao2023-11-12  131

    1.创建热点

    ZNCZ-WIFI ZFW123456

    2.建立xm1.lua 取得ip 192.168.191.2

    wifi.setmode(wifi.STATION) wifi.sta.config("ZNCZ-WIFI","ZFW123456") wifi.sta.connect() tmr.alarm(1,1000,1,function() if wifi.sta.getip()==nil then print("ip unavailable,Wating ...") else tmr.stop(1) print("Config done,ip is "..wifi.sta.getip()) end end)

    3.建立服务器

    sv = net.createServer(net.TCP,300) sv:listen(80,function(c) c:on("receive",function(c,msg) print("client let u "..msg.." led") if(msg=="1") then gpio.write(led, gpio.LOW) if(gpio.read(led)==0) then c:send("open succeed!") else c:send("open failed!") end else if(msg=="2") then gpio.write(led, gpio.HIGH) if(gpio.read(led)==1) then c:send("close succeed!") else c:send("close failed!") end end end end) c:send(" tcp connection..") end)

    4.手机创建 CLIENT

    ip: 192.168.192.1 端口 80 发送 1 开灯 发送 2 灭灯

    最新回复(0)