Lopy can't reconnect to access point after connection is lost.

  • Hi I wrote some code for my Lopy that should reconnect to my access point after the connection is lost. I'm using the latest firmware version 1.5.0.b2.

    Here's my code:

    import network
    from network import WLAN
    import utime
    class Wlan():
        _ssid = "ssid"
        _passw = "secret"
        wlan = network.WLAN(mode=WLAN.STA)
        connected = False
        def __init__(self, ssid, passw):
            self._ssid = ssid
            self._passw = passw
            self.connected = self.wlan.isconnected()
        def connect_to_hotspot(self):
            while not self.connected:
                print('scanning: ')
                networks = self.wlan.scan()
                for net in networks:
                    if net.ssid == self._ssid:  
                        print('found %s' % self._ssid)
                        self.wlan.connect(self._ssid, auth=(WLAN.WPA2, self._passw))
                        while not self.wlan.isconnected():
                        self.connected = True;
                if not self.connected:
                    print('not connected')
    wlan = Wlan("secret",  "ssid")
    while wlan.wlan.isconnected():
    print('wlan failed try to reconnect')
    wlan.connected = False

    The code runs and connects to my access point. After the connection is lost. I see that the Lopy is trying to reconnect and lists all the wlans. However, the Lopy can't find the network it previous connected to doesn’t show up. Even after disabling the wlan and enabling it again, it still can't find the right wireless network.

    If I cut the power for a view seconds and reboot, the wireless network is found and the Lopy connects.

    What’s going on? Please help.

Log in to reply

Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.