Skip to content

Commit

Permalink
Update groups http example
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Jul 16, 2024
1 parent ac84b37 commit 6e630a8
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions examples/adafruit_io_http/adafruit_io_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Adafruit IO HTTP API - Group Interactions
# Documentation: https://io.adafruit.com/api/docs/#groups
# adafruit_circuitpython_adafruitio with an esp32spi_socket
import datetime
import adafruit_datetime as datetime
import board
import busio
from digitalio import DigitalInOut
Expand All @@ -15,14 +15,25 @@


# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
# source control.
# "password" keys with your WiFi credentials, along with "aio_username" and "aio_key" for
# your Adafruit IO user/key. DO NOT share that file or commit it into Git or other source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
import os
if os.getenv("ADAFRUIT_AIO_USERNAME") and os.getenv("ADAFRUIT_AIO_KEY"):
secrets = {
"aio_username": os.getenv("ADAFRUIT_AIO_USERNAME", "Your_Username_Here"),
"aio_key": os.getenv("ADAFRUIT_AIO_KEY", "Your_Adafruit_IO_Key_Here"),
"ssid": os.getenv("CIRCUITPY_WIFI_SSID", ""),
"password": os.getenv("CIRCUITPY_WIFI_PASSWORD", ""),
}
else:
print(
"WiFi + Adafruit IO secrets are kept in secrets.py, please add them there!"
)
raise

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
Expand All @@ -46,6 +57,11 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

# If you are using a wifi based mcu use this instead of esp code above, remove the from
# adafruit_esp32spi import line, optionally esp.connect(secrets["ssid"], secrets["password"])
# import wifi
# esp = wifi.radio

# Initialize a requests session
pool = adafruit_connection_manager.get_radio_socketpool(esp)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
Expand Down Expand Up @@ -84,9 +100,17 @@
print("Getting fresh humidity feed info... (notice groups)")
print(io.get_feed(humidity_feed["key"]))

# fetch current time
print("Fetching current time from IO... ", end="")
year, month, day, hour, minute, second, *_ = io.receive_time()
old_time = datetime.datetime(year, month, day, hour, minute, second)
print(old_time.isoformat())

# Publish data for multiple feeds to a group, use different timestamps for no reason
print("Publishing batch data to group feeds with created_at set 99minutes ago...")
thetime = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(minutes=99)
thetime = old_time - datetime.timedelta(minutes=99)
print(thetime)

io.send_group_data(
group_key=sensor_group["key"],
feeds_and_data=[
Expand Down

0 comments on commit 6e630a8

Please sign in to comment.