list wifi
for network in wifi.radio.start_scanning_networks():
print(f"{network.ssid} [Ch:{network.channel}] RSSI: {network.rssi}")
connect to wifi
wifi.radio.connect(ssid, password)
print wifi info
if wifi.radio.connected:
print("wifi SSID info = ",wifi.radio.ap_info.ssid)
print('transmit power', wifi.radio.tx_power)
print(f"My MAC address: {[hex(i) for i in wifi.radio.mac_address]}")
print("radio enabled", wifi.radio.enabled)
print("host name", wifi.radio.hostname)
fetch HTTP request
# Initalize Wifi, Socket Pool, Request Session
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
requests = adafruit_requests.Session(pool, ssl_context)
with requests.get("http://webpage.site") as response:
print(response.text)
CircuitPython Tricks
get the network time
# specific to the MatrixPortal M4
pool = adafruit_connection_manager.get_radio_socketpool(matrix.network._wifi.esp)
# most modern boards
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio),
# get the time
ntp = adafruit_ntp.NTP(socketpool=pool)
# print the time
print(ntp.datetime)
For the MagTag use magtag.get_local_time(), but you’ll need to setup the Adafruit IO credentials in settings.toml.
magtag.get_local_time() # sync with the network time
now = time.localtime()