![Adafruit AirLift Shield ESP32 Скачать руководство пользователя страница 33](http://html.mh-extra.com/html/adafruit/airlift-shield-esp32/airlift-shield-esp32_manual_2845848033.webp)
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
Содержание AirLift Shield ESP32
Страница 20: ...Adafruit Industries https learn adafruit com adafruit airlift shield esp32 wifi co processor Page 20 of 56...
Страница 40: ...Adafruit Industries https learn adafruit com adafruit airlift shield esp32 wifi co processor Page 40 of 56...
Страница 56: ...Adafruit Industries Last Updated 2021 03 29 01 04 51 PM EDT Page 56 of 56...