diff --git a/examples/luftdaten.py b/examples/luftdaten.py index 84f1117..c57e92d 100755 --- a/examples/luftdaten.py +++ b/examples/luftdaten.py @@ -73,7 +73,8 @@ def read_values(): # Get CPU temperature to use for compensation def get_cpu_temperature(): - process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True) + process = Popen(['vcgencmd', 'measure_temp'], + stdout=PIPE, universal_newlines=True) output, _error = process.communicate() return float(output[output.index('=') + 1:output.rindex("'")]) @@ -95,12 +96,13 @@ def check_wifi(): # Display Raspberry Pi serial and Wi-Fi status on LCD -def display_status(): - wifi_status = "connected" if check_wifi() else "disconnected" +def display_status(values): + # wifi_status = "connected" if check_wifi() else "disconnected" text_colour = (255, 255, 255) - back_colour = (0, 170, 170) if check_wifi() else (85, 15, 15) - id = get_serial_number() - message = "{}\nWi-Fi: {}".format(id, wifi_status) + back_colour = (0, 170, 170) if values["Data2 "] <= 10 else (85, 15, 15) + # id = get_serial_number() + # message = "{}\nWi-Fi: {}".format(id, wifi_status) + message = values["Data2 "] img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0)) draw = ImageDraw.Draw(img) size_x, size_y = draw.textsize(message, font) @@ -111,47 +113,6 @@ def display_status(): disp.display(img) -def send_to_luftdaten(values, id): - pm_values = dict(i for i in values.items() if i[0].startswith("P")) - temp_values = dict(i for i in values.items() if not i[0].startswith("P")) - - pm_values_json = [{"value_type": key, "value": val} for key, val in pm_values.items()] - temp_values_json = [{"value_type": key, "value": val} for key, val in temp_values.items()] - - resp_1 = requests.post( - "https://api.luftdaten.info/v1/push-sensor-data/", - json={ - "software_version": "enviro-plus 0.0.1", - "sensordatavalues": pm_values_json - }, - headers={ - "X-PIN": "1", - "X-Sensor": id, - "Content-Type": "application/json", - "cache-control": "no-cache" - } - ) - - resp_2 = requests.post( - "https://api.luftdaten.info/v1/push-sensor-data/", - json={ - "software_version": "enviro-plus 0.0.1", - "sensordatavalues": temp_values_json - }, - headers={ - "X-PIN": "11", - "X-Sensor": id, - "Content-Type": "application/json", - "cache-control": "no-cache" - } - ) - - if resp_1.ok and resp_2.ok: - return True - else: - return False - - # Compensation factor for temperature comp_factor = 2.25 @@ -180,9 +141,10 @@ def send_to_luftdaten(values, id): values = read_values() print(values) if time_since_update > 145: - resp = send_to_luftdaten(values, id) + # resp = send_to_luftdaten(values, id) + display_status update_time = time.time() print("Response: {}\n".format("ok" if resp else "failed")) - display_status() + display_status(values) except Exception as e: print(e)