changeset 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
files vanlogger.py
diffstat 1 files changed, 17 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/vanlogger.py	Wed Sep 25 21:36:49 2019 +0930
+++ b/vanlogger.py	Wed Sep 25 21:48:36 2019 +0930
@@ -5,9 +5,10 @@
 sys.path.append('/home/pi/logger')
 import datetime
 import epro.epro as epro
-import giant.giant as giant
+import json
 import serial
 import sqlite3
+import subprocess
 import sys
 
 def create(cur):
@@ -43,35 +44,21 @@
 ''')
 
     cur.execute('''
-CREATE TABLE IF NOT EXISTS giantlog(
-    tstamp			INTEGER NOT NULL,
-	ac_act_power	REAL NOT NULL,
-	ac_app_power	REAL NOT NULL,
-	ac_frequency	REAL NOT NULL,
-	ac_volts		REAL NOT NULL,
-	batt_chr_curr	REAL NOT NULL,
-	batt_dis_curr	REAL NOT NULL,
-    battery_cap		REAL NOT NULL,
-	battery_volts	REAL NOT NULL,
-	batt_volt_ofs	REAL NOT NULL,
-	bus_voltage		REAL NOT NULL,
-	grid_frequency	REAL NOT NULL,
-	grid_volts		REAL NOT NULL,
-	hs_temperature	REAL NOT NULL,
-	load_pct		REAL NOT NULL,
-	pv1_chrg_pow	REAL NOT NULL,
-	pv1_current		REAL NOT NULL,
-	pv1_volts		REAL NOT NULL,
-	scc1_volts		REAL NOT NULL,
-    scc1_charging	BOOLEAN NOT NULL,
-    switch			BOOLEAN NOT NULL,
-	float_charge	BOOLEAN NOT NULL,
-    ac_charging 	BOOLEAN NOT NULL,
-	sbu_prio		BOOLEAN NOT NULL,
-	b_volt_steady	BOOLEAN NOT NULL,
-    charging		BOOLEAN NOT NULL
+CREATE TABLE IF NOT EXISTS victron(
+    tstamp		INTEGER NOT NULL,
+    ACIn_L1_volts	REAL NOT NULL,
+    ACIn_L1_freq	REAL NOT NULL,
+    ACIn_L1_curent	REAL NOT NULL,
+    ACIn_active		BOOLEAN NOT NULL,
+    ACOut_L1_volts	REAL NOT NULL,
+    ACOut_L1_freq	REAL NOT NULL,
+    ACOut_L1_curent	REAL NOT NULL,
+    Battery_Voltage	REAL NOT NULL,
+    Battery_Current	REAL NOT NULL
 );
 ''')
+ 
+
 
 def log_epro(p, cur):
     # Check we have all the packets we need in the queue
@@ -135,61 +122,23 @@
     row['tstamp'] = int(datetime.datetime.now().strftime('%s'))
     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)
 
-def log_giant(gstat, cur):
-    row = {}
-    row['ac_act_power'] = gstat['ACActPower']
-    row['ac_app_power'] = gstat['ACAppPower']
-    row['ac_frequency'] = gstat['ACFreq']
-    row['ac_volts'] = gstat['ACVolts']
-    row['batt_chr_curr'] = gstat['BattChrCurr']
-    row['batt_dis_curr'] = gstat['BattDisCurr']
-    row['battery_cap'] = gstat['BattCap']
-    row['battery_volts'] = gstat['BattVolts']
-    row['batt_volt_ofs'] = gstat['BattVoltOfs']
-    row['bus_voltage'] = gstat['BusVolts']
-    row['grid_frequency'] = gstat['GridFreq']
-    row['grid_volts'] = gstat['GridVolts']
-    row['hs_temperature'] = gstat['HSTemp']
-    row['load_pct'] = gstat['LoadPct']
-    row['pv1_chrg_pow'] = gstat['PVChrgPow1']
-    row['pv1_current'] = gstat['PVCurr1']
-    row['pv1_volts'] = gstat['PVVolt1']
-    row['scc1_volts'] = gstat['SCC1Volt']
-    row['scc1_charging'] = gstat['Status']['SCC1Charging']
-    row['switch'] = gstat['Status']['Switch']
-    row['float_charge'] = gstat['Status']['FloatCharge']
-    if gstat['Status']['ChargeType'] == 'Both' or gstat['Status']['ChargeType'] == 'AC':
-        row['ac_charging'] = True
-    else:
-        row['ac_charging'] = False
-    row['sbu_prio'] = gstat['Status']['SBUPrio']
-    row['b_volt_steady'] = gstat['Status']['BattVoltSteady']
-    row['charging'] = gstat['Status']['Charging']
-
-    row['tstamp'] = int(datetime.datetime.now().strftime('%s'))
-    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)
-    s = serial.Serial('/dev/ttyS0', 2400, parity='E')
+    #s = serial.Serial('/dev/ttyS0', 2400, parity='E')
+    s = serial.Serial('/dev/ttyS0', 2400)
     s.timeout = 0.2
 
     p = epro.Processor()
-    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
@@ -200,16 +149,5 @@
             log_epro(p, cur)
             dbh.commit()
 
-        gstat = None
-        try:
-            gstat = ips.getStatus()
-        except:
-            pass
-        if gstat != None and dolog:
-            lastgiantlog = datetime.datetime.now()
-            log_giant(gstat, cur)
-            dbh.commit()
-            #print(gstat)
-
 if __name__ == '__main__':
     main()