The REUSE specifications[1] are meant to make it explicit and easier to apply code licensing information for a project. The provided lint tool makes it easy to ensure all the content (code and not code) is tagged. Important notes: * All the code (and documentation) that otherwise didn't have an explicit license headers have been tagged with ladyada's copyright as per the LICENSE file. * favicon.ico and CODE_OF_CONDUCT.md have been synced from the source-of-truth repositories. * All configuration files have been tagged with ladyada's copyright and Unlicense[2]. The current REUSE recommendation is to use CC0-1.0, but that has… side effects. There's some discussion in [3] about the recommendation for likely-uncopyrightable files (such as configuration files). [1]: https://reuse.software/ [2]: https://unlicense.org/ [3]: https://github.com/fsfe/reuse-docs/issues/62
81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import board
|
|
import busio
|
|
from digitalio import DigitalInOut
|
|
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
|
|
from adafruit_esp32spi import adafruit_esp32spi
|
|
import adafruit_requests as requests
|
|
|
|
print("ESP32 SPI webclient test")
|
|
|
|
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
|
|
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
|
|
|
|
|
|
# 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 AirLift Shield:
|
|
# esp32_cs = DigitalInOut(board.D10)
|
|
# esp32_ready = DigitalInOut(board.D7)
|
|
# esp32_reset = DigitalInOut(board.D5)
|
|
|
|
# If you have an AirLift Featherwing or ItsyBitsy Airlift:
|
|
# esp32_cs = DigitalInOut(board.D13)
|
|
# esp32_ready = DigitalInOut(board.D11)
|
|
# esp32_reset = DigitalInOut(board.D12)
|
|
|
|
# If you have an externally connected ESP32:
|
|
# NOTE: You may need to change the pins to reflect your wiring
|
|
# esp32_cs = DigitalInOut(board.D9)
|
|
# esp32_ready = DigitalInOut(board.D10)
|
|
# esp32_reset = DigitalInOut(board.D5)
|
|
|
|
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...")
|
|
while not esp.is_connected:
|
|
try:
|
|
esp.connect_AP(b"MY_SSID_NAME", b"MY_SSID_PASSWORD")
|
|
except RuntimeError as e:
|
|
print("could not connect to AP, retrying: ", e)
|
|
continue
|
|
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"))
|
|
|
|
# esp._debug = True
|
|
print("Fetching text from", TEXT_URL)
|
|
r = requests.get(TEXT_URL)
|
|
print("-" * 40)
|
|
print(r.text)
|
|
print("-" * 40)
|
|
r.close()
|
|
|
|
print()
|
|
print("Fetching json from", JSON_URL)
|
|
r = requests.get(JSON_URL)
|
|
print("-" * 40)
|
|
print(r.json())
|
|
print("-" * 40)
|
|
r.close()
|
|
|
|
print("Done!")
|