adding ItsyBitsy ESP32 CP WiFi test
This commit is contained in:
parent
7b505c04b3
commit
adb084d2b5
5 changed files with 68 additions and 68047 deletions
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 170 KiB |
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
|
@ -0,0 +1,68 @@
|
|||
# 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")
|
||||
Loading…
Reference in a new issue