
spi
=
busio.SPI(board.SCK, board.MOSI, board.MISO)
esp
=
adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)
if
esp.status
==
adafruit_esp32spi.WL_IDLE_STATUS:
(
"ESP32 found and in idle mode"
)
(
"Firmware vers."
, esp.firmware_version)
(
"MAC addr:"
, [
hex
(i)
for
i
in
esp.MAC_address])
for
ap
in
esp.scan_networks():
(
"\t%s\t\tRSSI: %d"
%
(
str
(ap[
"ssid"
],
"utf-8"
), ap[
"rssi"
]))
(
"Connecting to AP..."
)
while
not
esp.is_connected:
try
:
esp.connect_AP(secrets[
"ssid"
], secrets[
"password"
])
except
RuntimeError
as
e:
(
"could not connect to AP, retrying: "
, e)
continue
(
"Connected to"
,
str
(esp.ssid,
"utf-8"
),
"\tRSSI:"
, esp.rssi)
(
"My IP address is"
, esp.pretty_ip(esp.ip_address))
(
"IP lookup adafruit.com: %s"
%
esp.pretty_ip(esp.get_host_by_name(
"adafruit.com"
))
)
(
"Ping google.com: %d ms"
%
esp.ping(
"google.com"
))
# esp._debug = True
(
"Fetching text from"
, TEXT_URL)
r
=
requests.get(TEXT_URL)
(
"-"
*
40
)
(r.text)
(
"-"
*
40
)
r.close()
()
(
"Fetching json from"
, JSON_URL)
r
=
requests.get(JSON_URL)
(
"-"
*
40
)
(r.json())
(
"-"
*
40
)
r.close()
(
"Done!"
)
And save it to your board, with the name
code.py
.
Don't forget you'll also need to create the
secrets.py
file as seen above, with your
WiFi ssid and password.
In a serial console, you should see something like the following. For more information
about connecting with a serial console, view the guide
(https://adafru.it/Bec)
.
©Adafruit Industries
Page 17 of 54