From 115ae6dba2cdc1db0e186d936b2cb105a59fc782 Mon Sep 17 00:00:00 2001 From: Javan Rasokat Date: Sun, 19 Apr 2020 19:16:07 +0200 Subject: [PATCH] fixes --- read_ds18b20.py | 16 +++++++++------- read_settings.py | 17 +++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/read_ds18b20.py b/read_ds18b20.py index 62bf7d5..56f9d3a 100644 --- a/read_ds18b20.py +++ b/read_ds18b20.py @@ -18,16 +18,18 @@ def measure_temperature(sensor): if 'device_id' not in sensor: sensor["device_id"] = "undefined" - if 'pin' in sensor and isinstance(sensor["pin"], (int)) and sensor["pin"] > 0: - print("GPIO" + str(sensor["pin"]) + " is defined as 3.3V power source for Ds18b20 '" + sensor["device_id"] + "'") - setup_gpio(sensor["pin"]) + if 'pin' in sensor: + gpio_3V = int(sensor["pin"]) + if gpio_3V > 0: - if sensor["device_id"] != "undefined": + print("GPIO" + str(gpio_3V) + " is defined as 3.3V power source for Ds18b20 '" + sensor["device_id"] + "'") + setup_gpio(gpio_3V) - if (os.path.isdir("/sys/bus/w1/devices/" + sensor["device_id"]) == False): - error_log("Info: Resetting 3.3V GPIO" + str(sensor["pin"]) + " because Ds18b20 with device-id '" + sensor["device_id"] + "' was missing.") - reset_ds18b20_3V(sensor["pin"]) + if (os.path.isdir("/sys/bus/w1/devices/" + sensor["device_id"]) == False) and sensor["device_id"] != "undefined": + error_log("Info: Resetting 3.3V GPIO" + str(gpio_3V) + " because Ds18b20 with device-id '" + sensor["device_id"] + "' was missing.") + reset_ds18b20_3V(gpio_3V) + if sensor["device_id"] != "undefined": # read 1-wire slave file with open('/sys/bus/w1/devices/' + sensor["device_id"] + '/w1_slave', 'r') as file: file_content = file.read() diff --git a/read_settings.py b/read_settings.py index c15656b..bf00f1a 100644 --- a/read_settings.py +++ b/read_settings.py @@ -65,19 +65,20 @@ def get_settings(): try: my_file = Path(settingsFile) my_abs_path = my_file.resolve() - + if str(getpwuid(os.stat(settingsFile).st_uid).pw_name) != "www-data": os.system("sudo chown www-data " + str(settingsFile)) if str(getgrgid(os.stat(settingsFile).st_gid).gr_name) != "www-data": os.system("sudo chgrp www-data " + str(settingsFile)) - - #Check wittypi_scheduleFile - if str(getpwuid(os.stat(wittypi_scheduleFile).st_uid).pw_name) != "www-data": - os.system("sudo chown www-data " + str(wittypi_scheduleFile)) - if str(getgrgid(os.stat(wittypi_scheduleFile).st_gid).gr_name) != "www-data": - os.system("sudo chgrp www-data " + str(wittypi_scheduleFile)) - + + # Check wittypi_scheduleFile + if os.path.exists(wittypi_scheduleFile): + if str(getpwuid(os.stat(wittypi_scheduleFile).st_uid).pw_name) != "www-data": + os.system("sudo chown www-data " + str(wittypi_scheduleFile)) + if str(getgrgid(os.stat(wittypi_scheduleFile).st_gid).gr_name) != "www-data": + os.system("sudo chgrp www-data " + str(wittypi_scheduleFile)) + with io.open(settingsFile, encoding="utf-8") as data_file: settings = json.loads(data_file.read()) except Exception as ex: