Last active
December 15, 2022 20:36
-
-
Save anecdata/613f9de22ae246e59ca581fbad7de749 to your computer and use it in GitHub Desktop.
wifi connect regression-tester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, time, wifi, socketpool | |
from secrets import secrets | |
SLEEP = 1 | |
pool = socketpool.SocketPool(wifi.radio) | |
def connect(): | |
try: | |
wifi.radio.connect(secrets['ssid'], secrets['password']) | |
except ConnectionError as e: | |
print("Connection Error:", e) | |
while True: | |
print(f"Connecting... ", end="") | |
wifi.radio.enabled = True | |
connect() | |
print(f"{wifi.radio.ipv4_address} ", end="") | |
if "2040" in os.uname().machine: | |
time.sleep(0.100) # sometimes needed for connection to complete | |
else: | |
print(f"RSSI={wifi.radio.ap_info.rssi} ", end="") # NotImplementedError | |
time.sleep(SLEEP) | |
print(f"Disconnecting... ") | |
wifi.radio.enabled = False | |
time.sleep(SLEEP) | |
Error codes and their meanings are here (my git blame from two years ago):
https://github.com/adafruit/circuitpython/blob/366cf4a048c1d19c7f548125acfcd4e3ae9171df/shared-bindings/wifi/Radio.h#L38
Added delay for raspberrypi
: wifi.radio.connect
and wifi.radio.ipv4_address
are slightly decoupled in this port.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Occasional
Connection Error: Unknown failure
with various numbers are fine, but they should be infrequent.