User Manual
Initializes the ESP32 over SPI using the SPI port and 3 control pins:
Tells our requests library the type of socket we're using (socket type varies by connectivity type - we'll be using
the adafruit_esp32spi_socket for this example). We'll also set the interface to an esp object. This is a little bit of a
hack, but it lets us use requests like CPython does.
Verifies an ESP32 is found, checks the firmware and MAC address
Performs a scan of all access points it can see and prints out the name and signal strength:
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)
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
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
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:
print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])
for ap in esp.scan_networks():
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
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"))
© Adafruit Industries https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi Page 93 of 187