-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathonewireMonitor_py3.py
More file actions
63 lines (48 loc) · 1.62 KB
/
onewireMonitor_py3.py
File metadata and controls
63 lines (48 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python3
#########################################################################################
#
# oneWireMonitor
#
# Written by Simon Kong for the Raspberry Pi
# V1.0 03/09/2019
#
# Monitor onewire temp directory and hard reset power to the DS18B20 if folder is not present.
import signal
import RPi.GPIO as GPIO
import time
import os
import datetime
# handle kill signal
def handle_exit(sig, frame):
raise(SystemExit)
# Handle kill signal
def setup_OSsignal():
signal.signal(signal.SIGTERM, handle_exit)
print("\n\n{} - starting OneWire monitor".format(datetime.datetime.now()))
setup_OSsignal()
try:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
GPIO.setup(17, GPIO.OUT)
while True:
# uncomment the next line, to log when the next cycle is starthing
print("{} - Starting new cycle".format(datetime.datetime.now()))
##############################################################################################
# change this according to the folder / DS18B20 serial to monitor ****************************
if (os.path.isdir("/sys/bus/w1/devices/28-XXXXXXXXXXXX") == False):
print("{} - Reseting OneWire".format(datetime.datetime.now()))
GPIO.output(17, GPIO.LOW)
time.sleep(3)
GPIO.output(17, GPIO.HIGH)
#time.sleep(5)
# sleep for 50 sec
time.sleep(50)
except KeyboardInterrupt:
print("Keyboard Inturrupt detected")
except SystemExit:
print("kill signal detected")
except:
print("Some other error detected")
finally:
# eigher way, do this before exit
print("{} - cleanning up GPIO pins".format(datetime.datetime.now()))
GPIO.cleanup()