Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JavanXD committed Apr 19, 2020
1 parent 24381fd commit 115ae6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
16 changes: 9 additions & 7 deletions read_ds18b20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 9 additions & 8 deletions read_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 115ae6d

Please sign in to comment.