From 597016633e1de36089a9eb3dba2d13d0d7215f5c Mon Sep 17 00:00:00 2001 From: John Holah Date: Fri, 26 Feb 2021 09:33:47 +0000 Subject: [PATCH 1/2] changed screen message --- examples/luftdaten.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/examples/luftdaten.py b/examples/luftdaten.py index 84f11177..3a227788 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,27 @@ 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) + # img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0)) + # draw = ImageDraw.Draw(img) + # size_x, size_y = draw.textsize(message, font) + # x = (WIDTH - size_x) / 2 + # y = (HEIGHT / 2) - (size_y / 2) + # draw.rectangle((0, 0, 160, 80), back_colour) + # draw.text((x, y), message, font=font, fill=text_colour) + # disp.display(img) + + # 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) @@ -115,8 +131,10 @@ 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()] + 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/", @@ -183,6 +201,6 @@ def send_to_luftdaten(values, id): resp = send_to_luftdaten(values, id) update_time = time.time() print("Response: {}\n".format("ok" if resp else "failed")) - display_status() + display_status(values) except Exception as e: print(e) From 93859322ce099ba4a9771ff5de5d935f1de30967 Mon Sep 17 00:00:00 2001 From: John Holah Date: Fri, 26 Feb 2021 09:38:03 +0000 Subject: [PATCH 2/2] Removed luftdaten post --- examples/luftdaten.py | 60 ++----------------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) diff --git a/examples/luftdaten.py b/examples/luftdaten.py index 3a227788..c57e92df 100755 --- a/examples/luftdaten.py +++ b/examples/luftdaten.py @@ -97,20 +97,6 @@ def check_wifi(): # Display Raspberry Pi serial and Wi-Fi status on LCD 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) - # img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0)) - # draw = ImageDraw.Draw(img) - # size_x, size_y = draw.textsize(message, font) - # x = (WIDTH - size_x) / 2 - # y = (HEIGHT / 2) - (size_y / 2) - # draw.rectangle((0, 0, 160, 80), back_colour) - # draw.text((x, y), message, font=font, fill=text_colour) - # disp.display(img) - # wifi_status = "connected" if check_wifi() else "disconnected" text_colour = (255, 255, 255) back_colour = (0, 170, 170) if values["Data2 "] <= 10 else (85, 15, 15) @@ -127,49 +113,6 @@ def display_status(values): 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 @@ -198,7 +141,8 @@ 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(values)