#----------------------------- # user/customPanels.py #------------------------------ from kivy.uix.relativelayout import RelativeLayout from panels.template import panelTemplate from kivy.properties import Clock from kivy.properties import StringProperty import requests import json #----------------------------------- # do all the grabbing the data here #----------------------------------- class ExamplePanel(panelTemplate): def __init__(self,**kwargs): super().__init__(**kwargs) self.updateData() Clock.schedule_interval(self.updateData,59) def updateData(self, *args): data = self.get_data() # set the kivy panel element text self.ids.example_label.text = data def get_data(self): try: # API endpoint URL for a PurpleAir AQI sensor url = "http://192.168.2.33/json" response = requests.get(url).json() return str(response['current_temp_f']) except: return "n/a" ''' This is example data from a PurpleAir... { "SensorId": "xx:xx:xx:xx:xx:xx", "DateTime": "2023/02/12T18:58:14z", "Geo": "myhostnamehere", "Mem": 15880, "memfrag": 25, "memfb": 11920, "memcs": 960, "Id": 211261, "lat": 47.123456, "lon": -122.123456, "Adc": 0.04, "loggingrate": 15, "place": "outside", "version": "7.02", "uptime": 4033734, "rssi": -65, "period": 120, "httpsuccess": 34724, "httpsends": 34729, "hardwareversion": "2.0", "hardwarediscovered": "2.0+BME280+PMSX003-B+PMSX003-A", "current_temp_f": 48, "current_humidity": 63, "current_dewpoint_f": 36, "pressure": 1012.46, "p25aqic_b": "rgb(255,255,0)", "pm2.5_aqi_b": 51, "pm1_0_cf_1_b": 7.64, "p_0_3_um_b": 1389.57, "pm2_5_cf_1_b": 12.14, "p_0_5_um_b": 409.69, "pm10_0_cf_1_b": 13.07, "p_1_0_um_b": 57.1, "pm1_0_atm_b": 7.64, "p_2_5_um_b": 8.28, "pm2_5_atm_b": 12.14, "p_5_0_um_b": 0.79, "pm10_0_atm_b": 13.07, "p_10_0_um_b": 0.38, "p25aqic": "rgb(255,255,0)", "pm2.5_aqi": 52, "pm1_0_cf_1": 8.21, "p_0_3_um": 1517.38, "pm2_5_cf_1": 12.5, "p_0_5_um": 459.74, "pm10_0_cf_1": 13.95, "p_1_0_um": 68.69, "pm1_0_atm": 8.21, "p_2_5_um": 4.31, "pm2_5_atm": 12.5, "p_5_0_um": 1.45, "pm10_0_atm": 13.95, "p_10_0_um": 0.24, "pa_latency": 292, "wlstate": "Connected", "status_0": 2, "status_1": 2, "status_2": 2, "status_3": 2, "status_4": 0, "status_5": 0, "status_7": 0, "status_8": 0, "status_9": 0, "ssid": "myssidhere" } '''