while not wlan.isconnected(): - Infinite Loop



  • Hi Team,
    After the latest update

    (sysname='LoPy', nodename='LoPy', release='1.5.0.b2', version='v1.8.6-412-gf55ba50 on 2017-01-28', machine='LoPy with ESP32')

    The below code is entering into an infinite Loop.Is wlan isConnected not working ?

    from network import WLAN
    from time import sleep_ms
    
    wifi_count=1
    while not wlan.isconnected():
        print('Connecting Wifi attempt-{}'.format(wifi_count))
        wlan.connect('XXXX-NetGear', auth=(WLAN.WPA2, 'booboo@123'), timeout=5000)
        sleep_ms(1000)
        wifi_count=wifi_count+1
        pass
    

    Thanks & regards,
    MK HB



  • @livius Thanks a lot :)



  • no it is not good
    look here for example:
    https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/wlan.html

    while not wlan.isconnected():
                machine.idle() # save power while waiting
    

    and questions:

    1. your router have dhcp enabled?
      if not then try setting fixed ip in your LoPY
      e.g.
    wlan.ifconfig(config=('192.168.1.120', '255.255.255.0', '192.168.1.1', '192.168.1.1'))
    
    1. Do you have MAC filtering in your router enabled?
      if yes you must add mac of your LoPy


  • Hi Guys,
    If we increase sleep_ms to 5 secs then it works ? Is that the proper way to do this ?

    Thanks & regards,
    MK HB


Log in to reply
 

Pycom on Twitter