From 00ba11d374d1919a1d2ea2bebf9a4fa1de99810b Mon Sep 17 00:00:00 2001 From: Javan R Date: Wed, 17 Apr 2019 19:31:49 +0200 Subject: [PATCH 1/6] reduced time to press --- main.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 92c9190..5e443b6 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ import threading import time -import RPi.GPIO as GPIO +import RPi.GPIO as GPIO from read_and_upload_all import start_measurement from read_settings import get_settings @@ -21,12 +21,15 @@ GPIO_LED = 21 # GPIO for led gpio = 17 # gpio for button, will be overwritten by settings.json +def miliseconds(): + return int(round(time.time() * 1000)) + def start_ap(): global isActive, GPIO_LED isActive = 1 # measurement shall start next time print("AccessPoint start") start_led() - GPIO.output(GPIO_LED, GPIO.HIGH) + GPIO.output(GPIO_LED, GPIO.HIGH) t1 = threading.Thread(target=client_to_ap_mode) #client_to_ap_mode() t1.start() @@ -35,7 +38,7 @@ def stop_ap(boot=0): isActive = 0 # measurement shall stop next time print("AccessPoint stop") stop_led() - GPIO.output(GPIO_LED, GPIO.LOW) + GPIO.output(GPIO_LED, GPIO.LOW) t2 = threading.Thread(target=ap_to_client_mode) #ap_to_client_mode() t2.start() @@ -66,22 +69,22 @@ def toggle_measurement(): def button_pressed(channel): global gpio - if GPIO.input(gpio): # if port == 1 - button_pressed_rising() - else: # if port != 1 - button_pressed_falling() + if GPIO.input(gpio): # if port == 1 + button_pressed_rising() + else: # if port != 1 + button_pressed_falling() def button_pressed_rising(): global time_start - time_start = time.time() + time_start = miliseconds() def button_pressed_falling(): global time_start, debug - time_end = time.time() + time_end = miliseconds() time_elapsed = time_end-time_start - MIN_SECONDS_TO_ELAPSE = 1 # seconds - MAX_SECONDS_TO_ELAPSE = 3 - if time_elapsed >= MIN_SECONDS_TO_ELAPSE and time_elapsed <= MAX_SECONDS_TO_ELAPSE: + MIN_TIME_TO_ELAPSE = 500 # miliseconds + MAX_TIME_TO_ELAPSE = 3000 + if time_elapsed >= MIN_TIME_TO_ELAPSE and time_elapsed <= MAX_TIME_TO_ELAPSE: time_start = 0 # reset to prevent multiple fallings from the same rising toggle_measurement() elif debug: @@ -104,13 +107,13 @@ def main(): # by default is AccessPoint down stop_ap(1) - + debug = settings["debug"] # flag to enable debug mode (HDMI output enabled and no rebooting) if not debug: # stop HDMI power (save energy) print("Shutting down HDMI to save engery.") stop_tv() - + # start as seperate background thread # because Taster pressing was not recognised measurement_stop = threading.Event() # create event to stop measurement @@ -139,4 +142,4 @@ def main(): error_log(e, "Unhandled Exception in Main") if not debug: time.sleep(60) - reboot() \ No newline at end of file + reboot() From 6b74274389ac98d700c430899e4c3a5d9ae6c9f1 Mon Sep 17 00:00:00 2001 From: Javan R Date: Wed, 17 Apr 2019 20:59:59 +0200 Subject: [PATCH 2/6] small changes --- main.py | 9 ++++----- utilities.py | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 5e443b6..0e84ce0 100644 --- a/main.py +++ b/main.py @@ -27,7 +27,7 @@ def miliseconds(): def start_ap(): global isActive, GPIO_LED isActive = 1 # measurement shall start next time - print("AccessPoint start") + print("Maintenance Mode: START - Connect yourself to HoneyPi-Wifi.") start_led() GPIO.output(GPIO_LED, GPIO.HIGH) t1 = threading.Thread(target=client_to_ap_mode) #client_to_ap_mode() @@ -36,7 +36,7 @@ def start_ap(): def stop_ap(boot=0): global isActive, GPIO_LED isActive = 0 # measurement shall stop next time - print("AccessPoint stop") + print("Maintenance Mode: STOP") stop_led() GPIO.output(GPIO_LED, GPIO.LOW) t2 = threading.Thread(target=ap_to_client_mode) #ap_to_client_mode() @@ -51,14 +51,13 @@ def close_script(): def toggle_measurement(): global isActive, measurement_stop, measurement - print("Button was pressed") if isActive == 0: - print("Button: Stop measurement") + print("Button was pressed: Stop measurement") # stop the measurement by event's flag measurement_stop.set() start_ap() # finally start AP else: - print("Button: Start measurement") + print("Button was pressed: Start measurement") if measurement.is_alive(): print("Warning: Thread should not be active anymore") measurement_stop.clear() # reset flag diff --git a/utilities.py b/utilities.py index 9760caa..5b09889 100644 --- a/utilities.py +++ b/utilities.py @@ -48,10 +48,10 @@ def client_to_ap_mode(): # Enable static ip os.system("sudo mv /etc/dhcpcd.conf.disabled /etc/dhcpcd.conf") # Restart DHCP server for IP Address - os.system("sudo service dhcpcd restart && systemctl daemon-reload") # & will execute command in the background + os.system("sudo systemctl restart dhcpcd.service && systemctl daemon-reload") # & will execute command in the background # restart AP Services os.system("sudo systemctl restart dnsmasq.service") - os.system("sudo systemctl restart hostapd.service || (systemctl unmask hostapd && systemctl enable hostapd && systemctl start hostapd)") # if restart fails because service is masked => unmask + os.system("sudo systemctl restart hostapd.service || (systemctl unmask hostapd && systemctl enable hostapd && systemctl start hostapd) &") # if restart fails because service is masked => unmask start_wlan() def ap_to_client_mode(): @@ -62,7 +62,7 @@ def ap_to_client_mode(): # Disable static ip os.system("sudo mv /etc/dhcpcd.conf /etc/dhcpcd.conf.disabled") # Restart DHCP server for IP Address - os.system("sudo service dhcpcd restart && systemctl daemon-reload") # & will execute command in the background + os.system("sudo systemctl restart dhcpcd.service && systemctl daemon-reload") # & will execute command in the background # Start WPA Daemon os.system("sudo wpa_supplicant -i wlan0 -D wext -c /etc/wpa_supplicant/wpa_supplicant.conf -B") # activate the wifi connection with Id=0 From 12807c5b080955d675919021b4e3a15df748f4e4 Mon Sep 17 00:00:00 2001 From: Javan R Date: Sat, 20 Apr 2019 20:44:24 +0200 Subject: [PATCH 3/6] added CSV Files --- .gitignore | 1 + main.py | 10 ++--- read_and_upload_all.py | 64 +++++++++++++++--------------- read_hx711.py | 2 +- read_max.py | 6 +-- read_settings.py | 4 +- HX711.py => sensors/HX711.py | 0 MAX31855.py => sensors/MAX31855.py | 0 MAX6675.py => sensors/MAX6675.py | 0 utilities.py | 28 ++++++++++--- write_csv.py | 36 +++++++++++++++++ 11 files changed, 103 insertions(+), 48 deletions(-) rename HX711.py => sensors/HX711.py (100%) rename MAX31855.py => sensors/MAX31855.py (100%) rename MAX6675.py => sensors/MAX6675.py (100%) create mode 100644 write_csv.py diff --git a/.gitignore b/.gitignore index f7c4d8c..51f96fd 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ error.log # ========================= *.pyc error.log +*.csv diff --git a/main.py b/main.py index 0e84ce0..805cbbe 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ from read_and_upload_all import start_measurement from read_settings import get_settings -from utilities import stop_tv, stop_led, start_led, error_log, reboot, client_to_ap_mode, ap_to_client_mode, blink_led +from utilities import stop_tv, stop_led, start_led, error_log, reboot, client_to_ap_mode, ap_to_client_mode, blink_led, miliseconds # global vars measurement = None @@ -19,10 +19,7 @@ debug = 0 # will be overriten by settings.json. you need to change the debug-mode in settings.json time_start = 0 # will be set by button_pressed event if the button is rised GPIO_LED = 21 # GPIO for led -gpio = 17 # gpio for button, will be overwritten by settings.json - -def miliseconds(): - return int(round(time.time() * 1000)) +gpio = 16 # gpio for button, will be overwritten by settings.json def start_ap(): global isActive, GPIO_LED @@ -36,7 +33,8 @@ def start_ap(): def stop_ap(boot=0): global isActive, GPIO_LED isActive = 0 # measurement shall stop next time - print("Maintenance Mode: STOP") + if not boot: + print("Maintenance Mode: STOP") stop_led() GPIO.output(GPIO_LED, GPIO.LOW) t2 = threading.Thread(target=ap_to_client_mode) #ap_to_client_mode() diff --git a/read_and_upload_all.py b/read_and_upload_all.py index e5f5629..d0c95e2 100644 --- a/read_and_upload_all.py +++ b/read_and_upload_all.py @@ -19,6 +19,7 @@ from read_max import measure_tc from read_settings import get_settings, get_sensors from utilities import reboot, error_log, shutdown +from write_csv import write_csv class MyRebootException(Exception): """Too many ConnectionErrors => Rebooting""" @@ -37,6 +38,7 @@ def start_measurement(measurement_stop): interval = settings["interval"] debug = settings["debug"] # flag to enable debug mode (HDMI output enabled and no rebooting) shutdownAfterTransfer = settings["shutdownAfterTransfer"] + offline = settings["offline"] # flag to enable offline csv storage if debug: print("Debug-Mode is enabled.") @@ -136,38 +138,38 @@ def start_measurement(measurement_stop): ts_fields.update(weight) # print all measurement values stored in ts_fields - try: - # python2 - for key, value in ts_fields.iteritems(): - print(key + ": " + str(value)) - except AttributeError: - # python3 - for key, value in ts_fields.items(): - print(key + ": " + str(value)) - - try: - # update ThingSpeak / transfer values - if len(ts_fields) > 0: - channel.update(ts_fields) - if debug: - error_log("Info: Data succesfully transfered to ThingSpeak.") - if connectionErros > 0: + for key, value in ts_fields.items(): + print(key + ": " + str(value)) + + if len(ts_fields) > 0: + if offline: + try: + write_csv(ts_fields) + if debug: + error_log("Info: Data succesfully saved to CSV-File.") + else: + try: + # update ThingSpeak / transfer values + channel.update(ts_fields) if debug: - error_log("Info: Connection Errors (" + str(connectionErros) + ") Counting resetet.") - # reset connectionErros because transfer succeded - connectionErros = 0 - except requests.exceptions.HTTPError as errh: - error_log(errh, "Http Error") - except requests.exceptions.ConnectionError as errc: - error_log(errc, "Error Connecting " + str(connectionErros)) - connectionErros += 1 - # multiple connectionErrors in a row => Exception - if connectionErros >= 5: - raise MyRebootException - except requests.exceptions.Timeout as errt: - error_log(errt, "Timeout Error") - except requests.exceptions.RequestException as err: - error_log(err, "Something Else") + error_log("Info: Data succesfully transfered to ThingSpeak.") + if connectionErros > 0: + if debug: + error_log("Info: Connection Errors (" + str(connectionErros) + ") Counting resetet.") + # reset connectionErros because transfer succeded + connectionErros = 0 + except requests.exceptions.HTTPError as errh: + error_log(errh, "Http Error") + except requests.exceptions.ConnectionError as errc: + error_log(errc, "Error Connecting " + str(connectionErros)) + connectionErros += 1 + # multiple connectionErrors in a row => Exception + if connectionErros >= 5: + raise MyRebootException + except requests.exceptions.Timeout as errt: + error_log(errt, "Timeout Error") + except requests.exceptions.RequestException as err: + error_log(err, "Something Else") # stop measurements after uploading once if interval == 1: diff --git a/read_hx711.py b/read_hx711.py index f53cec2..020e4f3 100644 --- a/read_hx711.py +++ b/read_hx711.py @@ -2,7 +2,7 @@ # This file is part of HoneyPi [honey-pi.de] which is released under Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0). # See file LICENSE or go to http://creativecommons.org/licenses/by-nc-sa/3.0/ for full license details. -from HX711 import HX711 +from sensors.HX711 import HX711 import RPi.GPIO as GPIO import time diff --git a/read_max.py b/read_max.py index 9f85538..9c251fc 100644 --- a/read_max.py +++ b/read_max.py @@ -2,8 +2,8 @@ # This file is part of HoneyPi [honey-pi.de] which is released under Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0). # See file LICENSE or go to http://creativecommons.org/licenses/by-nc-sa/3.0/ for full license details. -from MAX6675 import MAX6675 -from MAX31855 import MAX31855 +from sensors.MAX6675 import MAX6675 +from sensors.MAX31855 import MAX31855 import RPi.GPIO as GPIO def measure_tc(tc_sensor): @@ -48,4 +48,4 @@ def measure_tc(tc_sensor): if 'ts_field' in tc_sensor: return ({tc_sensor["ts_field"]: tc_temperature}) - return {} \ No newline at end of file + return {} diff --git a/read_settings.py b/read_settings.py index f0e14ee..c71ae0c 100644 --- a/read_settings.py +++ b/read_settings.py @@ -17,7 +17,7 @@ def get_settings(): my_abs_path = my_file.resolve() except OSError: # FileNotFoundError # doesn"t exist => default values - settings["button_pin"] = 17 + settings["button_pin"] = 16 settings["interval"] = 300 else: @@ -34,7 +34,7 @@ def check_vars(settings): if not settings["button_pin"]: raise Exception("button_pin is not defined.") except: - settings["button_pin"] = 17 + settings["button_pin"] = 16 try: if not 'debug' in settings: diff --git a/HX711.py b/sensors/HX711.py similarity index 100% rename from HX711.py rename to sensors/HX711.py diff --git a/MAX31855.py b/sensors/MAX31855.py similarity index 100% rename from MAX31855.py rename to sensors/MAX31855.py diff --git a/MAX6675.py b/sensors/MAX6675.py similarity index 100% rename from MAX6675.py rename to sensors/MAX6675.py diff --git a/utilities.py b/utilities.py index 5b09889..54f8fae 100644 --- a/utilities.py +++ b/utilities.py @@ -48,7 +48,7 @@ def client_to_ap_mode(): # Enable static ip os.system("sudo mv /etc/dhcpcd.conf.disabled /etc/dhcpcd.conf") # Restart DHCP server for IP Address - os.system("sudo systemctl restart dhcpcd.service && systemctl daemon-reload") # & will execute command in the background + os.system("sudo systemctl restart dhcpcd.service && sudo systemctl daemon-reload") # & will execute command in the background # restart AP Services os.system("sudo systemctl restart dnsmasq.service") os.system("sudo systemctl restart hostapd.service || (systemctl unmask hostapd && systemctl enable hostapd && systemctl start hostapd) &") # if restart fails because service is masked => unmask @@ -62,7 +62,7 @@ def ap_to_client_mode(): # Disable static ip os.system("sudo mv /etc/dhcpcd.conf /etc/dhcpcd.conf.disabled") # Restart DHCP server for IP Address - os.system("sudo systemctl restart dhcpcd.service && systemctl daemon-reload") # & will execute command in the background + os.system("sudo systemctl restart dhcpcd.service && sudo systemctl daemon-reload") # & will execute command in the background # Start WPA Daemon os.system("sudo wpa_supplicant -i wlan0 -D wext -c /etc/wpa_supplicant/wpa_supplicant.conf -B") # activate the wifi connection with Id=0 @@ -75,12 +75,30 @@ def reboot(): def shutdown(): os.system("sudo shutdown -h 0") +def miliseconds(): + return int(round(time.time() * 1000)) + +# reduce size if file is to big +def check_file(file, size=5, entries=10): + try: + # If bigger than 25MB + if os.path.getsize(file) > size * 1024: + readFile = open(file) + lines = readFile.readlines() + readFile.close() + w = open(file,'w') + # delete first 25 lines in file + # but skip first entry because it is header + del lines[1:entries] + w.writelines(lines) + w.close() + except FileNotFoundError: + pass + def error_log(e=None, printText=None): try: file = scriptsFolder + '/error.log' - # reset file if to big - if os.path.getsize(file) > 100 * 1024: - os.remove(file) + check_file(file, 10, 50) # reset file if it gets to big # generate printed text if printText and e: diff --git a/write_csv.py b/write_csv.py new file mode 100644 index 0000000..ca472d2 --- /dev/null +++ b/write_csv.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# This file is part of HoneyPi [honey-pi.de] which is released under Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0). +# See file LICENSE or go to http://creativecommons.org/licenses/by-nc-sa/3.0/ for full license details. + +import csv +import time +import os, sys +import io +from datetime import datetime +from utilities import scriptsFolder, check_file, error_log + +def write_csv(ts_fields): + try: + csv_file = scriptsFolder + '/HoneyPi.csv' + # Allowed ThingSpeak fields: + csv_columns = ['datetime','field1','field2','field3','field4','field5','field6','field7','field8','latitude','longitude','elevation','status'] + check_file(csv_file, 5, 10) + + # Create row with data + row = {} + row['datetime']=datetime.now() + for key, value in ts_fields.items(): + row[key]=str(value) + + # Write to CSV File + write_header = (not os.path.isfile(csv_file) or os.stat(csv_file).st_size == 0) # exists or is empty + with io.open(csv_file, 'a', newline='', encoding='utf8') as csvfile: + writer = csv.DictWriter(csvfile, fieldnames=csv_columns, extrasaction='ignore', delimiter = ',', lineterminator='\n') + if write_header: + writer.writeheader() # file doesn't exist yet, write a header + writer.writerow(row) + + except IOError as ex1: + error_log(ex1, "Write-CSV IOError") + except Exception as ex: + error_log(ex, "Write-CSV Exception") From a20f9b2bd3f17a2214294c402a1d73dcc684b006 Mon Sep 17 00:00:00 2001 From: Javan R Date: Sat, 20 Apr 2019 21:39:13 +0200 Subject: [PATCH 4/6] file paths --- utilities.py | 10 +++++----- write_csv.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/utilities.py b/utilities.py index 54f8fae..8c4726b 100644 --- a/utilities.py +++ b/utilities.py @@ -79,17 +79,17 @@ def miliseconds(): return int(round(time.time() * 1000)) # reduce size if file is to big -def check_file(file, size=5, entries=10): +def check_file(file, size=5, entries=25, skipFirst=0): try: - # If bigger than 25MB + # If bigger than 5MB if os.path.getsize(file) > size * 1024: readFile = open(file) lines = readFile.readlines() readFile.close() w = open(file,'w') # delete first 25 lines in file - # but skip first entry because it is header - del lines[1:entries] + # When CSV: skip first entry because it is header (skipFirst=1) + del lines[skipFirst:entries] w.writelines(lines) w.close() except FileNotFoundError: @@ -98,7 +98,7 @@ def check_file(file, size=5, entries=10): def error_log(e=None, printText=None): try: file = scriptsFolder + '/error.log' - check_file(file, 10, 50) # reset file if it gets to big + check_file(file) # reset file if it gets to big # generate printed text if printText and e: diff --git a/write_csv.py b/write_csv.py index ca472d2..c3d0b82 100644 --- a/write_csv.py +++ b/write_csv.py @@ -11,10 +11,10 @@ def write_csv(ts_fields): try: - csv_file = scriptsFolder + '/HoneyPi.csv' + csv_file = scriptsFolder + '/offline.csv' # Allowed ThingSpeak fields: csv_columns = ['datetime','field1','field2','field3','field4','field5','field6','field7','field8','latitude','longitude','elevation','status'] - check_file(csv_file, 5, 10) + check_file(csv_file, 5, 10, 1) # Create row with data row = {} From 8edec1d9309a27d720090f83e18ce8942069fe12 Mon Sep 17 00:00:00 2001 From: Javan R Date: Sat, 20 Apr 2019 21:49:29 +0200 Subject: [PATCH 5/6] fixed missing exception --- read_and_upload_all.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/read_and_upload_all.py b/read_and_upload_all.py index d0c95e2..e4eabfd 100644 --- a/read_and_upload_all.py +++ b/read_and_upload_all.py @@ -147,6 +147,8 @@ def start_measurement(measurement_stop): write_csv(ts_fields) if debug: error_log("Info: Data succesfully saved to CSV-File.") + except Exception as ex: + error_log(ex, "Exception") else: try: # update ThingSpeak / transfer values From ecd303061f13cdd8b508ceab8e296b408913b185 Mon Sep 17 00:00:00 2001 From: Javan R Date: Wed, 24 Apr 2019 16:44:35 +0200 Subject: [PATCH 6/6] added support for different offline measures, improved timing interval --- read_and_upload_all.py | 42 +++++++++++++++++++++++++----------------- read_max.py | 4 ++-- read_settings.py | 5 +++++ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/read_and_upload_all.py b/read_and_upload_all.py index e4eabfd..96e0697 100644 --- a/read_and_upload_all.py +++ b/read_and_upload_all.py @@ -76,7 +76,9 @@ def start_measurement(measurement_stop): # start at -6 because we want to get 6 values before we can filter some out counter = -6 + time_measured = 0 while not measurement_stop.is_set(): + counter += 1 # read values from sensors every second for (sensorIndex, sensor) in enumerate(ds18b20Sensors): @@ -84,21 +86,19 @@ def start_measurement(measurement_stop): if 'device_id' in sensor: read_unfiltered_temperatur_values(sensorIndex, sensor['device_id']) - # for testing: - #try: - # weight = measure_weight(weightSensors[0]) - # print("weight: " + str(list(weight.values())[0])) - #except IOError: - # print "IOError occurred" - #except TypeError: - # print "TypeError occurred" - #except IndexError: - # print "IndexError occurred" - # wait seconds of interval before next check # free ThingSpeak account has an upload limit of 15 seconds - if counter%interval == 0 or interval == 1: - print("Time over for a new measurement.") + time_now = time.time() + isTimeToMeasure = (time_now-time_measured >= interval) and counter > 0 # old: counter%interval == 0 + if isTimeToMeasure or interval == 1: + now = time.strftime("%H:%M", time.localtime(time_now)) + lastMeasurement = time.strftime("%H:%M", time.localtime(time_measured)) + if time_measured == 0: + print("First time measurement. Now: " + str(now)) + else: + print("Last measurement was at " + str(lastMeasurement)) + print("Time over for a new measurement. Time is now: " + str(now)) + time_measured = time.time() # filter the values out for (sensorIndex, sensor) in enumerate(ds18b20Sensors): @@ -142,14 +142,14 @@ def start_measurement(measurement_stop): print(key + ": " + str(value)) if len(ts_fields) > 0: - if offline: + if offline == 1 or offline == 3: try: write_csv(ts_fields) if debug: error_log("Info: Data succesfully saved to CSV-File.") except Exception as ex: error_log(ex, "Exception") - else: + if offline == 0 or offline == 1 or offline == 2: try: # update ThingSpeak / transfer values channel.update(ts_fields) @@ -165,13 +165,22 @@ def start_measurement(measurement_stop): except requests.exceptions.ConnectionError as errc: error_log(errc, "Error Connecting " + str(connectionErros)) connectionErros += 1 - # multiple connectionErrors in a row => Exception + + # Write to CSV-File if ConnectionError + if offline == 2: + write_csv(ts_fields) + if debug: + error_log("Info: Data succesfully saved to CSV-File.") + + # multiple connectionErrors in a row => MyRebootException if connectionErros >= 5: raise MyRebootException except requests.exceptions.Timeout as errt: error_log(errt, "Timeout Error") except requests.exceptions.RequestException as err: error_log(err, "Something Else") + except Exception as exTs: + error_log(exTs, "ThingSpeak Exception") # stop measurements after uploading once if interval == 1: @@ -183,7 +192,6 @@ def start_measurement(measurement_stop): sleep(10) shutdown() - counter += 1 sleep(0.96) end_time = time.time() diff --git a/read_max.py b/read_max.py index 9c251fc..4e5040a 100644 --- a/read_max.py +++ b/read_max.py @@ -20,7 +20,7 @@ def measure_tc(tc_sensor): except Exception as e: print("MAX6675/MAX31855 missing param: " + str(e)) - tc_temperature = 0 + tc_temperature = None # setup tc-Sensor try: @@ -46,6 +46,6 @@ def measure_tc(tc_sensor): except Exception as e: print("Reading MAX6675/MAX31855 failed: " + str(e)) - if 'ts_field' in tc_sensor: + if 'ts_field' in tc_sensor and tc_temperature is not None: return ({tc_sensor["ts_field"]: tc_temperature}) return {} diff --git a/read_settings.py b/read_settings.py index c71ae0c..f9dd30d 100644 --- a/read_settings.py +++ b/read_settings.py @@ -55,6 +55,11 @@ def check_vars(settings): settings["ts_channel_id"] = None settings["ts_write_key"] = None + try: + settings["offline"] + except KeyError: + settings["offline"] = 0 + return settings # get sensors by type