Skip to content

Commit ed1f9d4

Browse files
author
brentru
committed
add temp sensor, weather
1 parent f95ce6a commit ed1f9d4

File tree

2 files changed

+35
-43
lines changed

2 files changed

+35
-43
lines changed

examples/adafruit_io_http/adafruit_io_temperature.py

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,58 @@
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
93
import time
104
import board
115
import busio
126
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
2410
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
11+
import adafruit_adt7410
2512

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
2717
try:
2818
from secrets import secrets
2919
except ImportError:
3020
print("WiFi secrets are kept in secrets.py, please add them there!")
3121
raise
3222

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)
4232

4333
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
4434
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)
5147

5248
# Set your Adafruit IO Username and Key in secrets.py
5349
# (visit io.adafruit.com if you need to create an account,
5450
# or if you need your Adafruit IO key.)
5551
aio_username = secrets["aio_username"]
5652
aio_key = secrets["aio_key"]
5753

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)
6056

6157
try:
6258
# Get the 'temperature' feed from Adafruit IO

examples/adafruit_io_http/adafruit_io_weather.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
"""
2-
Example of getting weather
3-
from the Adafruit IO Weather Service
4-
NOTE: This example is for Adafruit IO
5-
Plus subscribers only.
6-
"""
1+
# Example of using the Adafruit IO+ Weather Service
2+
# adafruit_circuitpython_adafruitio with an esp32spi_socket
73
import time
84
import board
95
import busio

0 commit comments

Comments
 (0)