comparison vanlogger.py @ 22:59cf68be7feb

add trivial README
author Daniel O'Connor <darius@dons.net.au>
date Sun, 22 Jul 2018 12:54:05 +0930
parents f77cc29d0b47
children efe1954da8ca
comparison
equal deleted inserted replaced
13:3f22fa1f32d5 22:59cf68be7feb
6 import datetime 6 import datetime
7 import epro.epro as epro 7 import epro.epro as epro
8 import giant.giant as giant 8 import giant.giant as giant
9 import serial 9 import serial
10 import sqlite3 10 import sqlite3
11 import sys
11 12
12 def create(cur): 13 def create(cur):
13 cur.execute(''' 14 cur.execute('''
14 CREATE TABLE IF NOT EXISTS eprolog( 15 CREATE TABLE IF NOT EXISTS eprolog(
15 tstamp INTEGER NOT NULL, 16 tstamp INTEGER NOT NULL,
167 168
168 row['tstamp'] = int(datetime.datetime.now().strftime('%s')) 169 row['tstamp'] = int(datetime.datetime.now().strftime('%s'))
169 cur.execute('INSERT INTO giantlog VALUES(:tstamp, :ac_act_power, :ac_app_power, :ac_frequency, :ac_volts, :batt_chr_curr, :batt_dis_curr, :battery_cap, :battery_volts, :batt_volt_ofs, :bus_voltage, :grid_frequency, :grid_volts, :hs_temperature, :load_pct, :pv1_chrg_pow, :pv1_current, :pv1_volts, :scc1_volts, :scc1_charging, :switch, :float_charge, :ac_charging, :sbu_prio, :b_volt_steady, :charging)', row) 170 cur.execute('INSERT INTO giantlog VALUES(:tstamp, :ac_act_power, :ac_app_power, :ac_frequency, :ac_volts, :batt_chr_curr, :batt_dis_curr, :battery_cap, :battery_volts, :batt_volt_ofs, :bus_voltage, :grid_frequency, :grid_volts, :hs_temperature, :load_pct, :pv1_chrg_pow, :pv1_current, :pv1_volts, :scc1_volts, :scc1_charging, :switch, :float_charge, :ac_charging, :sbu_prio, :b_volt_steady, :charging)', row)
170 171
171 def main(): 172 def main():
173 print 'Started'
172 dbh = sqlite3.connect('/home/pi/vanlogger/log.db') 174 dbh = sqlite3.connect('/home/pi/vanlogger/log.db')
173 cur = dbh.cursor() 175 cur = dbh.cursor()
174 create(cur) 176 create(cur)
175 s = serial.Serial('/dev/ttyUSB0', 2400, parity='E') 177 s = serial.Serial('/dev/ttyS0', 2400, parity='E')
176 s.timeout = 0.2 178 s.timeout = 0.2
177 179
178 p = epro.Processor() 180 p = epro.Processor()
179 ips = giant.GiantIPS() 181 ips = giant.GiantIPS()
180 182
181 then = None 183 then = None
184 lasteprolog = datetime.datetime.now()
185 lastgiantlog = datetime.datetime.now()
182 while True: 186 while True:
187 if datetime.datetime.now() - lasteprolog > datetime.timedelta(hours = 1):
188 print('Stale ePro data')
189 sys.exit(1)
190 if datetime.datetime.now() - lastgiantlog > datetime.timedelta(hours = 1):
191 print('Stale Giant data')
192 sys.exit(1)
183 dolog = False 193 dolog = False
184 if then == None or datetime.datetime.now() - then > datetime.timedelta(seconds = 60): 194 if then == None or datetime.datetime.now() - then > datetime.timedelta(seconds = 60):
185 dolog = True 195 dolog = True
186 then = datetime.datetime.now() 196 then = datetime.datetime.now()
187 p.process(s.read(1024)) 197 p.process(s.read(1024))
188 if dolog: 198 if dolog:
199 lasteprolog = datetime.datetime.now()
189 log_epro(p, cur) 200 log_epro(p, cur)
190 dbh.commit() 201 dbh.commit()
191 202
192 gstat = None 203 gstat = None
193 try: 204 try:
194 gstat = ips.getStatus() 205 gstat = ips.getStatus()
195 except: 206 except:
196 pass 207 pass
197 if gstat != None and dolog: 208 if gstat != None and dolog:
209 lastgiantlog = datetime.datetime.now()
198 log_giant(gstat, cur) 210 log_giant(gstat, cur)
199 dbh.commit() 211 dbh.commit()
200 #print(gstat) 212 #print(gstat)
201 213
202 if __name__ == '__main__': 214 if __name__ == '__main__':