Skip to content

Commit d8ebe4c

Browse files
author
brentru
committed
add example for using the groups api
1 parent 2c1f65e commit d8ebe4c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Example of performing group operations
3+
"""
4+
import board
5+
import busio
6+
from digitalio import DigitalInOut
7+
8+
# ESP32 SPI
9+
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
10+
11+
# Import Adafruit IO REST Client
12+
from adafruit_io.adafruit_io import RESTClient
13+
14+
# Get wifi details and more from a wifi_settings.py.py file
15+
try:
16+
from wifi_settings import settings
17+
except ImportError:
18+
print("WiFi settings are kept in wifi_settings.py.py, please add them there!")
19+
raise
20+
21+
22+
# ESP32 Setup
23+
esp32_cs = DigitalInOut(board.D9)
24+
esp32_ready = DigitalInOut(board.D10)
25+
esp32_reset = DigitalInOut(board.D5)
26+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
27+
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
28+
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL)
29+
30+
"""
31+
# PyPortal ESP32 Setup
32+
import microcontroller
33+
esp32_cs = DigitalInOut(microcontroller.pin.PB14)
34+
esp32_ready = DigitalInOut(microcontroller.pin.PB16)
35+
esp32_reset = DigitalInOut(microcontroller.pin.PB17)
36+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
37+
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
38+
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL)
39+
"""
40+
41+
# Set your Adafruit IO Username and Key in wifi_settings.py
42+
# (visit io.adafruit.com if you need to create an account,
43+
# or if you need your Adafruit IO key.)
44+
ADAFRUIT_IO_USER = settings['adafruit_io_user']
45+
ADAFRUIT_IO_KEY = settings['adafruit_io_key']
46+
47+
# Create an instance of the Adafruit IO REST client
48+
io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi)
49+
50+
# Create a new group
51+
print('Creating a new Adafruit IO Group...')
52+
sensor_group = io.create_new_group('envsensors', 'a group of environmental sensors')
53+
54+
# Add the 'temperature' feed to the group
55+
print('Adding feed temperature to group...')
56+
io.add_feed_to_group(sensor_group['key'], 'temperature')
57+
58+
# Get info from the group
59+
print(sensor_group)
60+
61+
# Delete the group
62+
print('Deleting group...')
63+
io.delete_group('envsensors')

0 commit comments

Comments
 (0)