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 #28 background imageLoading...
Page #28 background image
for ap in esp.scan_networks():
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
Connects to the AP we've defined here, then prints out the local IP address, attempts to do a domain
name lookup and ping google.com to check network connectivity (note sometimes the ping fails or takes
a while, this isn't a big deal)
print("Connecting to AP...")
esp.connect_AP(b'MY_SSID_NAME', b'MY_SSID_PASSWORD')
print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
print("Ping google.com: %d ms" % esp.ping("google.com"))
OK now we're getting to the really interesting part. With a SAMD51 or other large-RAM (well, over 32 KB)
device, we can do a lot of neat tricks. Like for example we can implement an interface a lot like
requests (https://adafru.it/E9o) - which makes getting data
really really easy
To read in all the text from a web URL call requests.get - you can pass in https URLs for SSL connectivity
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print('-'*40)
print(r.text)
print('-'*40)
r.close()
Or, if the data is in structured JSON, you can get the json pre-parsed into a Python dictionary that can be
easily queried or traversed. (Again, only for nRF52840, M4 and other high-RAM boards)
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
print("Fetching json from", JSON_URL)
r = requests.get(JSON_URL)
print('-'*40)
print(r.json())
print('-'*40)
r.close()
Requests
We've written a requests-like (https://adafru.it/Kpa) library for web interfacing
named Adafruit_CircuitPython_Requests (https://adafru.it/FpW). This library allows you to send HTTP/1.1
requests without "crafting" them and provides helpful methods for parsing the response from the server.
Here's an example of using Requests to perform GET and POST requests to a server.
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# adafruit_requests usage with an esp32spi_socket
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
© Adafruit Industries https://learn.adafruit.com/adafruit-airlift-shield-esp32-wifi-co-processor Page 28 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)