File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 12
12
import terminalio
13
13
from adafruit_matrixportal .matrixportal import MatrixPortal
14
14
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
+
15
22
def aqi_transform (val ):
16
23
aqi = pm_to_aqi (val ) # derive Air Quality Index from Particulate Matter 2.5 value
17
24
return "AQI: %d" % aqi
@@ -32,16 +39,19 @@ def message_transform(val): # picks message based on thresholds
32
39
return "Unknown"
33
40
34
41
SENSOR_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"
37
44
SCROLL_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
39
46
40
47
# --- Display setup ---
41
48
matrixportal = MatrixPortal (
42
49
status_neopixel = board .NEOPIXEL ,
43
50
debug = True ,
44
51
url = DATA_SOURCE ,
52
+ headers = {"X-API-Key" : secrets ["purple_air_api_key" ], # purpleair.com
53
+ "Accept" : "application/json"
54
+ },
45
55
json_path = (DATA_LOCATION , DATA_LOCATION ),
46
56
)
47
57
You can’t perform that action at this time.
0 commit comments