Mercurial > ~darius > hgwebdir.cgi > vanlogger
diff vanlogger.py @ 23:efe1954da8ca
merge
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sun, 22 Jul 2018 12:56:29 +0930 |
parents | 65be58857ed4 59cf68be7feb |
children | 718b963b0dfa |
line wrap: on
line diff
--- a/vanlogger.py Wed Mar 14 00:23:52 2018 +1030 +++ b/vanlogger.py Sun Jul 22 12:56:29 2018 +0930 @@ -8,6 +8,7 @@ import giant.giant as giant import serial import sqlite3 +import sys def create(cur): cur.execute(''' @@ -169,6 +170,7 @@ 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) def main(): + print 'Started' dbh = sqlite3.connect('/home/pi/vanlogger/log.db') cur = dbh.cursor() create(cur) @@ -179,13 +181,22 @@ ips = giant.GiantIPS() then = None + lasteprolog = datetime.datetime.now() + lastgiantlog = datetime.datetime.now() while True: + if datetime.datetime.now() - lasteprolog > datetime.timedelta(hours = 1): + print('Stale ePro data') + sys.exit(1) + if datetime.datetime.now() - lastgiantlog > datetime.timedelta(hours = 1): + print('Stale Giant data') + sys.exit(1) dolog = False if then == None or datetime.datetime.now() - then > datetime.timedelta(seconds = 60): dolog = True then = datetime.datetime.now() p.process(s.read(1024)) if dolog: + lasteprolog = datetime.datetime.now() log_epro(p, cur) dbh.commit() @@ -195,6 +206,7 @@ except: pass if gstat != None and dolog: + lastgiantlog = datetime.datetime.now() log_giant(gstat, cur) dbh.commit() #print(gstat)