EasyManuals Logo

Adafruit AirLift Shield ESP32 User Manual

Adafruit AirLift Shield ESP32
57 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #33 background imageLoading...
Page #33 background image
socket.set_interface(esp)
requests.set_socket(socket, esp)
JSON_GET_URL = "http://httpbin.org/get"
# Define a custom header as a dict.
headers = {"user-agent": "blinka/1.0.0"}
print("Fetching JSON data from %s..." % JSON_GET_URL)
response = requests.get(JSON_GET_URL, headers=headers)
print("-" * 60)
json_data = response.json()
headers = json_data["headers"]
print("Response's Custom User-Agent Header: {0}".format(headers["User-Agent"]))
print("-" * 60)
# Read Response's HTTP status code
print("Response HTTP Status Code: ", response.status_code)
print("-" * 60)
# Close, delete and collect the response data
response.close()
WiFi Manager
That simpletest example works but its a little finicky - you need to constantly check WiFi status and have
many loops to manage connections and disconnections. For more advanced uses, we recommend using
the WiFiManager object. It will wrap the connection/status/requests loop for you - reconnecting if WiFi
drops, resetting the ESP32 if it gets into a bad state, etc.
Here's a more advanced example that shows the WiFi manager and also how to POST data with some
extra headers:
# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import busio
from digitalio import DigitalInOut
import neopixel
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
print("ESP32 SPI webclient test")
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
© Adafruit Industries https://learn.adafruit.com/adafruit-airlift-shield-esp32-wifi-co-processor Page 33 of 56

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit AirLift Shield ESP32 and is the answer not in the manual?

Adafruit AirLift Shield ESP32 Specifications

General IconGeneral
MicrocontrollerESP32
InterfaceSPI
WiFi802.11 b/g/n
Voltage Level3.3V
TypeShield
SD Card SocketNo
Wireless ConnectivityWiFi
Input Voltage5V
Flash Memory4 MB
SRAM520 KB
Clock Speed240 MHz
USBNo
Compatible BoardsArduino Uno, Mega
AntennaCeramic
Digital I/O PinsNot directly accessible (used for SPI communication)