# 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)
"""Use below for Most Boards"""
status_light = neopixel.NeoPixel(
board.NEOPIXEL, 1, brightness=0.2
) # Uncomment for Most Boards
"""Uncomment below for ItsyBitsy M4"""
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
# Uncomment below for an externally defined RGB LED
# import adafruit_rgbled
# from adafruit_esp32spi import PWMOut
# RED_LED = PWMOut.PWMOut(esp, 26)
# GREEN_LED = PWMOut.PWMOut(esp, 27)
# BLUE_LED = PWMOut.PWMOut(esp, 25)
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
counter = 0
while True:
try:
print("Posting data...", end="")
data = counter
feed = "test"
payload = {"value": data}
response = wifi.post(
"https://io.adafruit.com/api/v2/"
+ secrets["aio_username"]
+ "/feeds/"
+ feed
+ "/data",
json=payload,
headers={"X-AIO-KEY": secrets["aio_key"]},
)
print(response.json())
response.close()
counter = c 1
print("OK")
except (ValueError, RuntimeError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
continue
response = None
time.sleep(15)
You'll note here we use a secrets.py file to manage our SSID info. The wifimanager is given the ESP32
object, secrets and a neopixel for status indication.
Note, you'll need to add a some additional information to your secrets file so that the code can query the
Adafruit IO API:
aio_username
aio_key
You can go to your adafruit.io View AIO Key link to get those two values and add them to the secrets file,
which will now look something like this:
© Adafruit Industries
https://learn.adafruit.com/adafruit-airlift-shield-esp32-wifi-co-processor
Page 34 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...