-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjaguar-charging.py
84 lines (62 loc) · 2.6 KB
/
jaguar-charging.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
"""Charge logging script
This script will download the get_vehicle_status every 5 minutes
and log them locally. Based on the Charge Off-Peak script.
This script is independent from visualization script in order to run it on different computers
"""
import jlrpy
import threading
import datetime
import math
from datetime import date
import os
import configparser
# login info (email and password) are read from $HOME/.jlrpy.cfg
# which contains a single line with email and password separated by ':'
# [email protected]:PassW0rd
# passwords containing a ':' are not allowed
logger = jlrpy.logger
def check_soc():
"""Retrieve vehicle status.
"""
"""!missing: adjust logging frequency to charging speed:
> 100% every 1 Min
> 50% every 2 Min
> 0 every 5 Min
unpluged every 5 Min
"""
threading.Timer(2 * 60, check_soc).start() # Called every 2 minutes
# getting status update
status = { d['key'] : d['value'] for d in v.get_status()['vehicleStatus'] }
current_soc = int(status['EV_STATE_OF_CHARGE'])
charging_status = status['EV_CHARGING_STATUS']
logger.info("current SoC is "+str(current_soc)+"%")
if status['EV_CHARGING_METHOD'] == "WIRED":
logger.info("car is plugged in")
logger.info("charging status is "+charging_status)
p = v.get_position()
position = (p['position']['latitude'], p['position']['longitude'])
logger.info("car geo-position is "+str(position))
position = ", 'POSITION_LATITUDE': " + str(position[0]) + ", 'POSITION_LONGITUDE': " + str(position[1])
t = datetime.datetime.now()
clogfilename = "jaguar-logs/charging-log_" + t.strftime("%Y-%m-%d_%H-%M-%S") + ".json"
clogfile= open(clogfilename,"w+")
logger.info("writing charging log file " + clogfilename)
# getting health status forces a status update
healthstatus = v.get_health_status()
status = { d['key'] : d['value'] for d in v.get_status()['vehicleStatus']}
logtime = ", 'LOGTIMESTAMP': '"+ t.isoformat() +"'}"
clogfile.write(str(status).replace("}", "") + position + logtime)
clogfile.close()
else:
logger.info("car is not plugged in")
config = configparser.ConfigParser()
configfile = os.environ['HOME']+"/.jlrpy.ini"
config.read(configfile)
username = config['jlrpy']['email']
password = config['jlrpy']['password']
home = (float(config['jlrpy']['home_latitude']), float(config['jlrpy']['home_longitude']))
c = jlrpy.Connection(username, password)
v = c.vehicles[0]
logger.info("[*] Logging vehicle status")
check_soc()