-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduled.py
executable file
·45 lines (37 loc) · 1.25 KB
/
scheduled.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
#!/usr/bin/python
# Import required Python libraries
from datetime import datetime, time
import MySQLdb
import RPi.GPIO as GPIO
import time
from functions import dbfetch,dbupdate,dolog,relay_manual,relay_delay,sysreboot,mandiff
import logging
#Sleeping for 1 seconds
time.sleep(1)
#Running a loop to check for scheduled tasks
while True:
#Getting settings table from DB
irrigatedata = dbfetch('IRRIGATE_NOW','weather_settings')
rebootdata = dbfetch('REBOOTNOW','weather_settings')
if irrigatedata == 3:
difference = mandiff()
if difference/60 > 5:
irrigatedata = 2
else:
print("Time doesn't exceed 5 minutes")
if irrigatedata == 1:
dbupdate('IRRIGATE_NOW','weather_settings','3')
print("Irrigating now")
nowtime = time.strftime("%Y-%m-%d %H:%M:%S")
dbupdate('MANTIME','weather_settings',str(nowtime))
relay_manual('on')
if irrigatedata == 2:
dbupdate('IRRIGATE_NOW','weather_settings','0')
print("Stopping irrigation now")
relay_manual('off')
if rebootdata == 1:
dbupdate('REBOOTNOW','weather_settings','0')
time.sleep(10)
sysreboot()
#Sleeping for 5 seconds
time.sleep(5)