The code creates a socketpool using the wifi radio's available sockets. This is
performed so we don't need to re-use sockets. Then, it initializes a a new instance of
the
requests ()
interface - which makes getting data from the internet really really
easy.
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
To read in plain-text from a web URL, call
http, or a https url for SSL connectivity.
print("Fetching text from", TEXT_URL)
response = requests.get(TEXT_URL)
print("-" * 40)
print(response.text)
print("-" * 40)
Requests can also display a JSON-formatted response from a web URL using a call to
.
requests.get
print("Fetching json from", JSON_QUOTES_URL)
response = requests.get(JSON_QUOTES_URL)
print("-" * 40)
print(response.json())
print("-" * 40)
Finally, you can fetch and parse a JSON URL using
obtains the
stargazers_count
print("Fetching and parsing json from", JSON_STARS_URL)
response = requests.get(JSON_STARS_URL)
print("-" * 40)
print("CircuitPython GitHub Stars", response.json()["stargazers_count"])
print("-" * 40)
OK you now have your ESP32 board set up with a proper secrets.py file and can
connect over the Internet. If not, check that your secrets.py file has the right ssid and
password and retrace your steps until you get the Internet connectivity working!
Adafruit IO: Send and Receive Data
Adafruit IO gives you the option to disconnect your microcontroller from your
computer and run it off of USB power or a battery, and still be able to see the data. It
also allows you to send data to your microcontroller, such as NeoPixel colors. This
example shows how to both send data to and receive data from Adafruit IO. It pulls
©Adafruit Industries
requests.get
requests.get
field from a call to the GitHub API.
- you may pass in either a
. This code snippet
Page 147 of 263
Need help?
Do you have a question about the ESP32-S3 and is the answer not in the manual?