-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathchargecontroller.py
42 lines (33 loc) · 1015 Bytes
/
chargecontroller.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
#
#
#
import os
import time
import gpiozero
import db
import threading
from datetime import datetime
from consts import CHARGER_GPIO
from consts import CHARGER_RUNTIME
from consts import CHARGER_OFFTIME
chargeRelay = gpiozero.OutputDevice(CHARGER_GPIO, active_high = True,
initial_value = False)
def heartbeat():
entry = { 'timestamp': str(datetime.now().timestamp()),
'event': 'Heartbeat'}
db.logChargeRun(entry)
threading.Timer(600, heartbeat).start()
heartbeat()
while True:
# Stop charging
chargeRelay.off()
entry = { 'timestamp': str(datetime.now().timestamp()),
'event': 'Switch Off'}
db.logChargeRun(entry)
time.sleep(CHARGER_OFFTIME)
# Start charging
chargeRelay.on()
entry = { 'timestamp': str(datetime.now().timestamp()),
'event': 'Switch On'}
db.logChargeRun(entry)
time.sleep(CHARGER_RUNTIME)