-
Notifications
You must be signed in to change notification settings - Fork 2
/
dewheateron.py
58 lines (39 loc) · 1.08 KB
/
dewheateron.py
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
#
# dew-heater-test
#
# Dew heater turn off relay
#
import sys
import RPi.GPIO as GPIO
import json
ON = 1
OFF = 0
class ConfigClass:
def loadConfig(self):
try:
with open('/home/pi/dewheater/dewheaterconfig.json', 'r') as f:
self.configFile = json.load(f)
print(json.dumps(self.configFile, indent=4, sort_keys=True))
self.dewHeaterPin = self.configFile['dewHeaterPin']
except:
sys.stderr.flush()
sys.exit("\nError opening or parsing config file, exiting")
GPIO.setmode(GPIO.BCM)
GPIO.setup(config.dewHeaterPin, GPIO.OUT)
print("dew-heater-test started.")
return (True)
config = ConfigClass()
class DewHeaterClass:
def __init__(self):
self.status = OFF
def on(self):
GPIO.output(config.dewHeaterPin, GPIO.HIGH)
self.status = ON
print("Dew heater on")
dewHeater = DewHeaterClass()
def main():
config.loadConfig()
print("Turning dew heater ON")
dewHeater.on()
if __name__ == "__main__":
main()