-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoisture.py
37 lines (31 loc) · 928 Bytes
/
moisture.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
#!/usr/bin/python3
# custom
import camera
import pump
import gardentools
# raspberry pi specific
import RPi.GPIO as GPIO
def main():
config = gardentools.get_config()
moisture_pin = config['moisture_sensor']['pin']
GPIO.setmode(GPIO.BOARD)
GPIO.setup(moisture_pin, GPIO.IN, GPIO.PUD_DOWN)
dry = GPIO.input(moisture_pin)
if dry:
dry = True
if config['pump']['enabled'] and config['pump']['frequency'] == 'when dry':
watered = pump.pump()
else:
watered = None
if config['camera']['enabled'] and config['pump']['frequency'] == 'when dry':
photo = camera.take_picture()
else:
photo = None
else:
dry = False
watered = None
photo = None
with gardentools.Logs('opengardener.db') as db:
db.write(dry=dry, photo_path=photo, watered=watered)
if __name__ == '__main__':
main()