|
1 |
| -""" |
2 |
| -Example of sending temperature |
3 |
| -values to an Adafruit IO feed. |
4 |
| -
|
5 |
| -Dependencies: |
6 |
| - * CircuitPython_ADT7410 |
7 |
| - https://github.com/adafruit/Adafruit_CircuitPython_ADT7410 |
8 |
| -""" |
| 1 | +# Example of sending ADT7410 sensor temperature values to IO |
| 2 | +# adafruit_circuitpython_adafruitio with an esp32spi_socket |
9 | 3 | import time
|
10 | 4 | import board
|
11 | 5 | import busio
|
12 | 6 | from digitalio import DigitalInOut
|
13 |
| - |
14 |
| -# ESP32 SPI |
15 |
| -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager |
16 |
| - |
17 |
| -# Import NeoPixel Library |
18 |
| -import neopixel |
19 |
| - |
20 |
| -# Import ADT7410 Library |
21 |
| -import adafruit_adt7410 |
22 |
| - |
23 |
| -# Import Adafruit IO HTTP Client |
| 7 | +import adafruit_esp32spi.adafruit_esp32spi_socket as socket |
| 8 | +from adafruit_esp32spi import adafruit_esp32spi |
| 9 | +import adafruit_requests as requests |
24 | 10 | from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
|
| 11 | +import adafruit_adt7410 |
25 | 12 |
|
26 |
| -# Get wifi details and more from a secrets.py file |
| 13 | +# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and |
| 14 | +# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other |
| 15 | +# source control. |
| 16 | +# pylint: disable=no-name-in-module,wrong-import-order |
27 | 17 | try:
|
28 | 18 | from secrets import secrets
|
29 | 19 | except ImportError:
|
30 | 20 | print("WiFi secrets are kept in secrets.py, please add them there!")
|
31 | 21 | raise
|
32 | 22 |
|
33 |
| -# ESP32 Setup |
34 |
| -try: |
35 |
| - esp32_cs = DigitalInOut(board.ESP_CS) |
36 |
| - esp32_ready = DigitalInOut(board.ESP_BUSY) |
37 |
| - esp32_reset = DigitalInOut(board.ESP_RESET) |
38 |
| -except AttributeError: |
39 |
| - esp32_cs = DigitalInOut(board.D9) |
40 |
| - esp32_ready = DigitalInOut(board.D10) |
41 |
| - esp32_reset = DigitalInOut(board.D5) |
| 23 | +# If you are using a board with pre-defined ESP32 Pins: |
| 24 | +esp32_cs = DigitalInOut(board.ESP_CS) |
| 25 | +esp32_ready = DigitalInOut(board.ESP_BUSY) |
| 26 | +esp32_reset = DigitalInOut(board.ESP_RESET) |
| 27 | + |
| 28 | +# If you have an externally connected ESP32: |
| 29 | +# esp32_cs = DigitalInOut(board.D9) |
| 30 | +# esp32_ready = DigitalInOut(board.D10) |
| 31 | +# esp32_reset = DigitalInOut(board.D5) |
42 | 32 |
|
43 | 33 | spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
44 | 34 | esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
45 |
| -status_light = neopixel.NeoPixel( |
46 |
| - board.NEOPIXEL, 1, brightness=0.2 |
47 |
| -) # Uncomment for Most Boards |
48 |
| -"""Uncomment below for ItsyBitsy M4""" |
49 |
| -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) |
50 |
| -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) |
| 35 | + |
| 36 | +print("Connecting to AP...") |
| 37 | +while not esp.is_connected: |
| 38 | + try: |
| 39 | + esp.connect_AP(secrets["ssid"], secrets["password"]) |
| 40 | + except RuntimeError as e: |
| 41 | + print("could not connect to AP, retrying: ", e) |
| 42 | + continue |
| 43 | +print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi) |
| 44 | + |
| 45 | +socket.set_interface(esp) |
| 46 | +requests.set_socket(socket, esp) |
51 | 47 |
|
52 | 48 | # Set your Adafruit IO Username and Key in secrets.py
|
53 | 49 | # (visit io.adafruit.com if you need to create an account,
|
54 | 50 | # or if you need your Adafruit IO key.)
|
55 | 51 | aio_username = secrets["aio_username"]
|
56 | 52 | aio_key = secrets["aio_key"]
|
57 | 53 |
|
58 |
| -# Create an instance of the Adafruit IO HTTP client |
59 |
| -io = IO_HTTP(aio_username, aio_key, wifi) |
| 54 | +# Initialize an Adafruit IO HTTP API object |
| 55 | +io = IO_HTTP(aio_username, aio_key, requests) |
60 | 56 |
|
61 | 57 | try:
|
62 | 58 | # Get the 'temperature' feed from Adafruit IO
|
|
0 commit comments