The wifi.sta module connects if a loop is running?

前端 未结 2 1235
我寻月下人不归
我寻月下人不归 2021-01-27 15:12

Im trying to detect when the module actually connects to my wifi AP, since .connect does not have a callback im doing something simple like this:

wifi.sta.config         


        
2条回答
  •  耶瑟儿~
    2021-01-27 15:51

    Using tmr.delay doesnot let run the event loop, you should use a timer callback.

    Then the code could be something like :

    wifi.sta.config("SSID","password")
    wifi.sta.connect()
    
    i=0
    tmr.alarm(1, 1000, 1, function()
        if (wifi.sta.status() ~= 5 and i < 10) then
           print("Status:"..wifi.sta.status())
           i = i + 1
        else
           tmr.stop(1)
           if (wifi.sta.status() == 5) then
              print("IP:"..wifi.sta.getip())
           else
              print("Status:"..wifi.sta.status())
           end
        end
    end)
    

提交回复
热议问题