Merge pull request #2535 from makermelissa/purple-air-update

It uses Secrets verses settings.toml which is the new method but as this is an update it should be ok
This commit is contained in:
Anne Barela 2023-06-14 17:44:45 -04:00 committed by GitHub
commit 2717b7e5f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,13 @@ import board
import terminalio import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal from adafruit_matrixportal.matrixportal import MatrixPortal
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
def aqi_transform(val): def aqi_transform(val):
aqi = pm_to_aqi(val) # derive Air Quality Index from Particulate Matter 2.5 value aqi = pm_to_aqi(val) # derive Air Quality Index from Particulate Matter 2.5 value
return "AQI: %d" % aqi return "AQI: %d" % aqi
@ -32,16 +39,19 @@ def message_transform(val): # picks message based on thresholds
return "Unknown" return "Unknown"
SENSOR_ID = 3085 # Poughkeepsie # 30183 LA outdoor / 37823 oregon / 21441 NYC SENSOR_ID = 3085 # Poughkeepsie # 30183 LA outdoor / 37823 oregon / 21441 NYC
SENSOR_REFRESH_PERIOD = 30 # seconds SENSOR_REFRESH_PERIOD = 300 # seconds
DATA_SOURCE = "https://www.purpleair.com/json?show=" + str(SENSOR_ID) DATA_SOURCE = f"https://api.purpleair.com/v1/sensors/{SENSOR_ID}?fields=pm2.5_10minute"
SCROLL_DELAY = 0.02 SCROLL_DELAY = 0.02
DATA_LOCATION = ["results", 0, "PM2_5Value"] # navigate the JSON response DATA_LOCATION = ["sensor", "stats", "pm2.5_10minute"] # navigate the JSON response
# --- Display setup --- # --- Display setup ---
matrixportal = MatrixPortal( matrixportal = MatrixPortal(
status_neopixel=board.NEOPIXEL, status_neopixel=board.NEOPIXEL,
debug=True, debug=True,
url=DATA_SOURCE, url=DATA_SOURCE,
headers={"X-API-Key": secrets["purple_air_api_key"], # purpleair.com
"Accept": "application/json"
},
json_path=(DATA_LOCATION, DATA_LOCATION), json_path=(DATA_LOCATION, DATA_LOCATION),
) )