Skip to content

Commit c9c0346

Browse files
committed
fix native wifi test code for bundler
1 parent e24c6a0 commit c9c0346

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SPDX-FileCopyrightText: 2020 Brent Rubell for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import ipaddress
6+
import ssl
7+
import wifi
8+
import socketpool
9+
import adafruit_requests
10+
11+
# URLs to fetch from
12+
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
13+
JSON_QUOTES_URL = "https://www.adafruit.com/api/quotes.php"
14+
JSON_STARS_URL = "https://api.github.com/repos/adafruit/circuitpython"
15+
16+
# Get wifi details and more from a secrets.py file
17+
try:
18+
from secrets import secrets
19+
except ImportError:
20+
print("WiFi secrets are kept in secrets.py, please add them there!")
21+
raise
22+
23+
print("ESP32-S2 WebClient Test")
24+
25+
print("My MAC addr:", [hex(i) for i in wifi.radio.mac_address])
26+
27+
print("Available WiFi networks:")
28+
for network in wifi.radio.start_scanning_networks():
29+
print("\t%s\t\tRSSI: %d\tChannel: %d" % (str(network.ssid, "utf-8"),
30+
network.rssi, network.channel))
31+
wifi.radio.stop_scanning_networks()
32+
33+
print("Connecting to %s"%secrets["ssid"])
34+
wifi.radio.connect(secrets["ssid"], secrets["password"])
35+
print("Connected to %s!"%secrets["ssid"])
36+
print("My IP address is", wifi.radio.ipv4_address)
37+
38+
ipv4 = ipaddress.ip_address("8.8.4.4")
39+
print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
40+
41+
pool = socketpool.SocketPool(wifi.radio)
42+
requests = adafruit_requests.Session(pool, ssl.create_default_context())
43+
44+
print("Fetching text from", TEXT_URL)
45+
response = requests.get(TEXT_URL)
46+
print("-" * 40)
47+
print(response.text)
48+
print("-" * 40)
49+
50+
print("Fetching json from", JSON_QUOTES_URL)
51+
response = requests.get(JSON_QUOTES_URL)
52+
print("-" * 40)
53+
print(response.json())
54+
print("-" * 40)
55+
56+
print()
57+
58+
print("Fetching and parsing json from", JSON_STARS_URL)
59+
response = requests.get(JSON_STARS_URL)
60+
print("-" * 40)
61+
print("CircuitPython GitHub Stars", response.json()["stargazers_count"])
62+
print("-" * 40)
63+
64+
print("done")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2020 Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Public Domain
4+
5+
# This file is where you keep secret settings, passwords, and tokens!
6+
# If you put them in the code you risk committing that info or sharing it
7+
8+
secrets = {
9+
'ssid' : 'home_wifi_network',
10+
'password' : 'wifi_password',
11+
'aio_username' : 'my_adafruit_io_username',
12+
'aio_key' : 'my_adafruit_io_key',
13+
'timezone' : "America/New_York", # http://worldtimeapi.org/timezones
14+
}

0 commit comments

Comments
 (0)