/ examples / adafruit_io_http / adafruit_io_groups.py
adafruit_io_groups.py
 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 NeoPixel Library
12  import neopixel
13  
14  # Import Adafruit IO HTTP Client
15  from adafruit_io.adafruit_io import IO_HTTP
16  
17  # Get wifi details and more from a secrets.py file
18  try:
19      from secrets import secrets
20  except ImportError:
21      print("WiFi secrets are kept in secrets.py, please add them there!")
22      raise
23  
24  # ESP32 Setup
25  try:
26      esp32_cs = DigitalInOut(board.ESP_CS)
27      esp32_ready = DigitalInOut(board.ESP_BUSY)
28      esp32_reset = DigitalInOut(board.ESP_RESET)
29  except AttributeError:
30      esp32_cs = DigitalInOut(board.D9)
31      esp32_ready = DigitalInOut(board.D10)
32      esp32_reset = DigitalInOut(board.D5)
33  
34  spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
35  esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
36  status_light = neopixel.NeoPixel(
37      board.NEOPIXEL, 1, brightness=0.2
38  )  # Uncomment for Most Boards
39  """Uncomment below for ItsyBitsy M4"""
40  # status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
41  wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
42  # Set your Adafruit IO Username and Key in secrets.py
43  # (visit io.adafruit.com if you need to create an account,
44  # or if you need your Adafruit IO key.)
45  aio_username = secrets["aio_username"]
46  aio_key = secrets["aio_key"]
47  
48  # Create an instance of the Adafruit IO HTTP client
49  io = IO_HTTP(aio_username, aio_key, wifi)
50  
51  # Create a new group
52  print("Creating a new Adafruit IO Group...")
53  sensor_group = io.create_new_group("envsensors", "a group of environmental sensors")
54  
55  # Add the 'temperature' feed to the group
56  print("Adding feed temperature to group...")
57  io.add_feed_to_group(sensor_group["key"], "temperature")
58  
59  # Get info from the group
60  print(sensor_group)
61  
62  # Delete the group
63  print("Deleting group...")
64  io.delete_group("envsensors")