Here's an example testing WiFi connectivity with the ItsyBitsy ESP32 with Web Workflow.
Download the Project Bundle
In the example below, click the Download Project Bundle button to download the necessary library and Python files in a zip file. Then, extract the contents of the zip file.
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries # # SPDX-License-Identifier: MIT import os import ipaddress import ssl import wifi import socketpool import adafruit_requests # URLs to fetch from TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html" JSON_QUOTES_URL = "https://www.adafruit.com/api/quotes.php" JSON_STARS_URL = "https://api.github.com/repos/adafruit/circuitpython" print("ItsyBitsy ESP32 WebClient Test") print(f"My MAC address: {[hex(i) for i in wifi.radio.mac_address]}") print("Available WiFi networks:") for network in wifi.radio.start_scanning_networks(): print("\t%s\t\tRSSI: %d\tChannel: %d" % (str(network.ssid, "utf-8"), network.rssi, network.channel)) wifi.radio.stop_scanning_networks() print(f"Connecting to {os.getenv('CIRCUITPY_WIFI_SSID')}") wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")) print(f"Connected to {os.getenv('CIRCUITPY_WIFI_SSID')}") print(f"My IP address: {wifi.radio.ipv4_address}") ping_ip = ipaddress.IPv4Address("8.8.8.8") ping = wifi.radio.ping(ip=ping_ip) # retry once if timed out if ping is None: ping = wifi.radio.ping(ip=ping_ip) if ping is None: print("Couldn't ping 'google.com' successfully") else: # convert s to ms print(f"Pinging 'google.com' took: {ping * 1000} ms") pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) print(f"Fetching text from {TEXT_URL}") response = requests.get(TEXT_URL) print("-" * 40) print(response.text) print("-" * 40) print(f"Fetching json from {JSON_QUOTES_URL}") response = requests.get(JSON_QUOTES_URL) print("-" * 40) print(response.json()) print("-" * 40) print() print(f"Fetching and parsing json from {JSON_STARS_URL}") response = requests.get(JSON_STARS_URL) print("-" * 40) print(f"CircuitPython GitHub Stars: {response.json()['stargazers_count']}") print("-" * 40) print("Done")
Upload the Project Bundle with Web Workflow
Follow these steps to add the /lib folder and code.py file from the Project Bundle to the ItsyBitsy ESP32 with Web Workflow.
Navigate to where you downloaded the Project Bundle and select the /lib folder. Click Upload to upload the folder to the device.
You'll be prompted in the browser to confirm that you want to upload the folder. Click Upload to proceed.
When the /lib folder has been successfully uploaded, you will see a message below the file directory that says "Uploaded 2 of 2".
Now you'll upload the code.py file. Click the first Browse... button (for files) to bring up a file explorer window.
Navigate to where you downloaded the Project Bundle and select the code.py file. Click Open to upload the file to the device.
When the file has successfully uploaded, you'll see "Uploaded 1 out of 1 files" appear below the directory listing.
Your code will immediately start running. To see the serial output, you can head back to the main Welcome! screen by clicking on Blinka (the purple snake).
On the Welcome! screen, click on the serial terminal link. This will take you to the serial terminal window.
Text editor powered by tinymce.