Skip to content

Commit d642a9c

Browse files
authored
Merge pull request #2114 from ladyada/main
factory demo for kb2040
2 parents 3df4f11 + 3e906a1 commit d642a9c

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-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: Unlicense
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+
}

Factory_Tests/KB2040_FactoryTest/.feather_rp2040.test.only

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-FileCopyrightText: 2022 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include "Adafruit_TestBed.h"
6+
7+
extern Adafruit_TestBed TB;
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
//while (!Serial) { yield(); delay(10); } // wait till serial port is opened
12+
delay(100); // RP2040 delay is not a bad idea
13+
14+
Serial.println("KB2040 self-tester!");
15+
16+
TB.neopixelPin = 17;
17+
TB.neopixelNum = 1;
18+
19+
TB.begin();
20+
}
21+
22+
uint8_t x = 0;
23+
24+
void loop() {
25+
TB.setColor(TB.Wheel(x++));
26+
delay(10);
27+
}

0 commit comments

Comments
 (0)