File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import terminalio
1313from adafruit_matrixportal .matrixportal import MatrixPortal
1414
15+ # Get wifi details and more from a secrets.py file
16+ try :
17+ from secrets import secrets
18+ except ImportError :
19+ print ("WiFi secrets are kept in secrets.py, please add them there!" )
20+ raise
21+
1522def aqi_transform (val ):
1623 aqi = pm_to_aqi (val ) # derive Air Quality Index from Particulate Matter 2.5 value
1724 return "AQI: %d" % aqi
@@ -32,16 +39,19 @@ def message_transform(val): # picks message based on thresholds
3239 return "Unknown"
3340
3441SENSOR_ID = 3085 # Poughkeepsie # 30183 LA outdoor / 37823 oregon / 21441 NYC
35- SENSOR_REFRESH_PERIOD = 30 # seconds
36- DATA_SOURCE = "https://www .purpleair.com/json?show=" + str ( SENSOR_ID )
42+ SENSOR_REFRESH_PERIOD = 300 # seconds
43+ DATA_SOURCE = f "https://api .purpleair.com/v1/sensors/ { SENSOR_ID } ?fields=pm2.5_10minute"
3744SCROLL_DELAY = 0.02
38- DATA_LOCATION = ["results " , 0 , "PM2_5Value " ] # navigate the JSON response
45+ DATA_LOCATION = ["sensor " , "stats" , "pm2.5_10minute " ] # navigate the JSON response
3946
4047# --- Display setup ---
4148matrixportal = MatrixPortal (
4249 status_neopixel = board .NEOPIXEL ,
4350 debug = True ,
4451 url = DATA_SOURCE ,
52+ headers = {"X-API-Key" : secrets ["purple_air_api_key" ], # purpleair.com
53+ "Accept" : "application/json"
54+ },
4555 json_path = (DATA_LOCATION , DATA_LOCATION ),
4656)
4757
You can’t perform that action at this time.
0 commit comments