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 boot.py 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.
Daniel
# boot.py 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() wl.disconnect() wl.mode(WLAN.STA) try: # Select one of these two ifconfig()s #wl.ifconfig(config=('192.168.17.210', '255.255.255.0', '192.168.17.1', '192.168.17.2')) wl.ifconfig(config='dhcp') 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 machine.idle() # Check final status if wl.isconnected(): print("\nConnected to WiFi") print(wl.ifconfig()) else: print("\nWiFi not connected") except: 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, "255.255.255.0", "10.0.0.240", "10.0.0.240")) 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 break print('.', end='') time.sleep_ms(200) else: print("Connect attempt timed out\n") return print('\nnetwork config:', wlan.ifconfig())