Skip to content

Instantly share code, notes, and snippets.

@anecdata
Last active December 15, 2022 20:36
Show Gist options
  • Save anecdata/613f9de22ae246e59ca581fbad7de749 to your computer and use it in GitHub Desktop.
Save anecdata/613f9de22ae246e59ca581fbad7de749 to your computer and use it in GitHub Desktop.
wifi connect regression-tester
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)
@anecdata
Copy link
Author

Occasional Connection Error: Unknown failure with various numbers are fine, but they should be infrequent.

@anecdata
Copy link
Author

anecdata commented Oct 26, 2022

@anecdata
Copy link
Author

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