Cannot get WiPy 3 to work as station (WLAN.STA)

  • Hi,

    I have two WiPy boards on an expansion 3 board. I'm having the same trouble with both getting them to communicate in Wi-Fi STA mode with a variety of software releases. Other aspects of the WiPy device appear to work, eg. flashing the RGBLed, and it can be put into AP mode and I can successfully authenticate with it from another Wi-Fi device.

    I've pasted my code below (hiding SSID/password etc), but what I am observing is that:

    • with a static ifconfig, the unit associates (authenticates) with my home Wi-Fi AP, but is not reachable with ping on the assigned address. Further, I can see no evidence that any packets are sent by the WiPy as the ARP does not complete with the ping, and I do not see the WiPy MAC address in my home switch.
    • with static ifconfig, but the incorrect password, the unit does not associate. This proves the unit is talking to my AP at one level.
    • with dhcp ifconfig, the unit associates but the DHCP does not complete and again, no evidence of any packets sent on the switch or DHCP server.

    I guess there might be an incompatibility between the AP and the WiPy, but I'd like to check my code first.

    I've tried this code on three releases:

    • 1.18.2.r1 (as supplied with the WiPy)
    • 1.20.0.rc13
    • 1.20.2.rc7

    Thanks for any assistance.


    import machine
    import os
    print("Starting boot...")
    from network import WLAN
    wl = WLAN(mode=WLAN.STA)
    # save the default ssid and auth
    original_ssid = wl.ssid()
    original_auth = wl.auth()
        # Select one of these two ifconfig()s
        #wl.ifconfig(config=('', '', '', ''))
        wl.connect('<REDACTED>', auth=(WLAN.WPA2, '<REDACTED>'), timeout=5000)
        # Progress indicator
        n = 0
        while not wl.isconnected():
            n += 1
            if n > 2500:
                print(".", end="")
                n = 0
        # Check final status
        if wl.isconnected():
            print("\nConnected to WiFi")
            print("\nWiFi not connected")
        print("\nReverting to WiFi AP")
        wl.init(mode=WLAN.AP, ssid=original_ssid, auth=original_auth, channel=6, antenna=WLAN.INT_ANT)
    print("Finishing boot...")

  • @robert-hh Thanks I agree busy-waiting is bad, my understanding was that machine.idle() would give other threads/interrupts the opportunity to run. That code was added to aid the debugging, to see activity while waiting for the network layer to configure itself.

    I've substituted your code but unfortunately it hasn't changed the networking behaviour - still no IP layer connectivity.

  • This post is deleted!

  • @danielk Instead of busy waiting, I have time.sleep(0.5) in the loop. In my experience, busy waiting makes it hard to connect.
    Edit: The code I use is:

    def do_connect():
        import network
        import time
        from uos import uname
        wlan = network.WLAN(mode=network.WLAN.STA) # create station interface
        if not wlan.isconnected():      # check if the station is connected to an AP
            wlan.ifconfig(config=(WIFI_IP, "", "",  ""))
            wlan.connect(ssid=WIFI_SSID, auth=(network.WLAN.WPA2, WIFI_PASSWD))
            for _ in range(100):
                if wlan.isconnected():      # check if the station is connected to an AP
                print('.', end='')
                print("Connect attempt timed out\n")
        print('\nnetwork config:', wlan.ifconfig())

Pycom on Twitter