annotate vanlogger.py @ 28:1da02c79b458

remove giant logging again due to merge screwup
author Daniel O'Connor <darius@dons.net.au>
date Wed, 25 Sep 2019 21:48:36 +0930
parents 718b963b0dfa
children e86e839febca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #!/usr/bin/env python
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 import sys
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 sys.path.append('/home/pi/logger')
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 import datetime
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 import epro.epro as epro
28
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
8 import json
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 import serial
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 import sqlite3
28
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
11 import subprocess
24
bacb798e6731 Remove giant code since the unit is dead.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
12 import sys
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 def create(cur):
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 cur.execute('''
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 CREATE TABLE IF NOT EXISTS eprolog(
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 tstamp INTEGER NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 main_voltage REAL NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 aux_voltage REAL NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 battery_curr REAL NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 amp_hours REAL NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 state_of_charge REAL NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 time_remaining REAL NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 battery_temp REAL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 auto_sync_volts BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 auto_sync_curr BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 e501 BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 alarm_test BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 light BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 display_test BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 temp_sensor BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 aux_hv BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 aux_lv BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 installer_lock BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 main_hv BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 main_lv BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 low_battery BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 battery_flat BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 battery_full BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 battery_charged BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 no_sync BOOLEAN NOT NULL,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 monitor_reset BOOLEAN NOT NULL
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 );
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 ''')
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 cur.execute('''
28
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
47 CREATE TABLE IF NOT EXISTS victron(
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
48 tstamp INTEGER NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
49 ACIn_L1_volts REAL NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
50 ACIn_L1_freq REAL NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
51 ACIn_L1_curent REAL NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
52 ACIn_active BOOLEAN NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
53 ACOut_L1_volts REAL NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
54 ACOut_L1_freq REAL NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
55 ACOut_L1_curent REAL NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
56 Battery_Voltage REAL NOT NULL,
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
57 Battery_Current REAL NOT NULL
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 );
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 ''')
28
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
60
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
61
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 def log_epro(p, cur):
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 # Check we have all the packets we need in the queue
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 msgtypes = set([x.msgtype for x in p.packets])
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 wantedtypes = set([
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 epro.MainVoltage.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 epro.AmpHours.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 epro.BatteryCurrent.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 epro.StateOfCharge.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 epro.TimeRemaining.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 epro.BatteryTemperature.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 epro.MonitorStatus.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 epro.AuxVoltage.MSGTYPE,
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 ])
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 if msgtypes < wantedtypes:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 return
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 row = {}
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 usedtypes = set()
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 while len(p.packets) > 0:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 pkt = p.packets.pop() # Read latest packets first
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 if pkt.msgtype == epro.MainVoltage.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 row['main_voltage'] = pkt.volts
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 elif pkt.msgtype == epro.AmpHours.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 row['amp_hours'] = pkt.amphrs
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 elif pkt.msgtype == epro.BatteryCurrent.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 row['battery_curr'] = pkt.amps
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 elif pkt.msgtype == epro.StateOfCharge.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 row['state_of_charge'] = pkt.soc
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 elif pkt.msgtype == epro.TimeRemaining.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 row['time_remaining'] = pkt.time
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 elif pkt.msgtype == epro.BatteryTemperature.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 row['battery_temp'] = pkt.temp
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 elif pkt.msgtype == epro.MonitorStatus.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 row['auto_sync_volts'] = pkt.autosyncvolt
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 row['auto_sync_curr'] = pkt.autosyncamp
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 row['e501'] = pkt.e501compat
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 row['alarm_test'] = pkt.alarmtst
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 row['light'] = pkt.backlight
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 row['display_test'] = pkt.disptst
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 row['temp_sensor'] = pkt.tempsense
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 row['aux_hv'] = pkt.auxhv
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 row['aux_lv'] = pkt.auxlv
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 row['installer_lock'] = pkt.lock
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 row['main_hv'] = pkt.mainhv
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 row['main_lv'] = pkt.mainlv
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 row['low_battery'] = pkt.lowbatalarm
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 row['battery_flat'] = pkt.batflat
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 row['battery_full'] = pkt.batfull
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 row['battery_charged'] = pkt.charged
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 row['no_sync'] = pkt.nosync
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 row['monitor_reset'] = pkt.monreset
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 elif pkt.msgtype == epro.AuxVoltage.MSGTYPE:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 row['aux_voltage'] = pkt.volts
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 usedtypes.add(pkt.msgtype)
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 if usedtypes >= wantedtypes:
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 p.packets = []
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 break
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 row['tstamp'] = int(datetime.datetime.now().strftime('%s'))
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 cur.execute('INSERT INTO eprolog VALUES (:tstamp, :main_voltage, :aux_voltage, :battery_curr, :amp_hours, :state_of_charge, :time_remaining, :battery_temp, :auto_sync_volts, :auto_sync_curr, :e501, :alarm_test, :light, :display_test, :temp_sensor, :aux_hv, :aux_lv, :installer_lock, :main_hv, :main_lv, :low_battery, :battery_flat, :battery_full, :battery_charged, :no_sync, :monitor_reset)', row)
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 def main():
24
bacb798e6731 Remove giant code since the unit is dead.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
126 print 'Started'
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 dbh = sqlite3.connect('/home/pi/vanlogger/log.db')
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 cur = dbh.cursor()
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 create(cur)
28
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
130 #s = serial.Serial('/dev/ttyS0', 2400, parity='E')
1da02c79b458 remove giant logging again due to merge screwup
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
131 s = serial.Serial('/dev/ttyS0', 2400)
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 s.timeout = 0.2
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134 p = epro.Processor()
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 then = None
24
bacb798e6731 Remove giant code since the unit is dead.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
137 lasteprolog = datetime.datetime.now()
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 while True:
24
bacb798e6731 Remove giant code since the unit is dead.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
139 if datetime.datetime.now() - lasteprolog > datetime.timedelta(hours = 1):
bacb798e6731 Remove giant code since the unit is dead.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
140 print('Stale ePro data')
bacb798e6731 Remove giant code since the unit is dead.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
141 sys.exit(1)
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142 dolog = False
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143 if then == None or datetime.datetime.now() - then > datetime.timedelta(seconds = 60):
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 dolog = True
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 then = datetime.datetime.now()
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 p.process(s.read(1024))
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 if dolog:
24
bacb798e6731 Remove giant code since the unit is dead.
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
148 lasteprolog = datetime.datetime.now()
0
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 log_epro(p, cur)
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150 dbh.commit()
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 if __name__ == '__main__':
78148730d98d Log ePro and Giant IPS status to sqlite DB
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 main()