In this example, you'll test your Metro ESP32-S3 WiFi connection by connecting to your WiFi, printing your MAC address and IP address to the serial console, and pinging Google.
CircuitPython WiFi Example
Click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, find your CircuitPython version, and copy the matching code.py file to your CIRCUITPY drive.
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries # # SPDX-License-Identifier: MIT import os import ipaddress import wifi import socketpool print() print("Connecting to WiFi") # connect to your SSID wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD')) print("Connected to WiFi") pool = socketpool.SocketPool(wifi.radio) # prints MAC address to REPL print("My MAC addr:", [hex(i) for i in wifi.radio.mac_address]) # prints IP address to REPL print("My IP address is", wifi.radio.ipv4_address) # pings Google ipv4 = ipaddress.ip_address("8.8.4.4") print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
CIRCUITPY

Add Your settings.toml File
Remember to add your settings.toml file as described earlier in this guide. You'll need to include your CIRCUITPY_WIFI_SSID
and CIRCUITPY_WIFI_PASSWORD
in the file.
CIRCUITPY_WIFI_SSID = "your-ssid-here" CIRCUITPY_WIFI_PASSWORD = "your-ssid-password-here"
Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
How the CircuitPython WiFi Example Works
In the basic WiFi test, the board connects to your SSID by importing your SSID and SSID password from the settings.toml file.
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
Then, your MAC address and IP address are printed to the REPL.
# prints MAC address to REPL print("My MAC addr:", [hex(i) for i in wifi.radio.mac_address]) # prints IP address to REPL print("My IP address is", wifi.radio.ipv4_address)
Finally, google.com is pinged. The amount of time it takes to ping is printed to the REPL and the code stops running.
# pings Google ipv4 = ipaddress.ip_address("8.8.4.4") print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
By successfully running this WiFi test code, you can confirm that your board is connecting to WiFi with CircuitPython successfully and you can move on to more advanced projects.
Page last edited March 08, 2024
Text editor powered by tinymce.