nodemcu远程连接点亮小灯

wifi.setmode(wifi.STATION)  
wifi.sta.config("CMCC-5tiu","123445") --手机热点的名称和密码
wifi.sta.connect()  --接入手机热点
gpio.write(0, gpio.LOW)
gpio.write(1, gpio.HIGH)
cl = net.createConnection(net.TCP, 0)
Tcp=0

function ledPWM()                   

    if(Tcp==0)then
        Tcp=1
        
        cl:connect(19660, "192.168.1.5")
    end
end
tmr.alarm(0, 5000, tmr.ALARM_AUTO, ledPWM)


cl:on("receive", function(sck, c) 

    print(sck)
   
    if(c=='0')then

        gpio.write(0, gpio.HIGH)
        gpio.write(1, gpio.LOW)
    else 
        print("sss")
        gpio.write(0, gpio.LOW)
        gpio.write(1, gpio.HIGH)
    end
    

end)
cl:on("disconnection", function(sck, c) print("disconnection!") end)

你可能感兴趣的:(单片机)