changeset 23:efe1954da8ca

merge
author Daniel O'Connor <darius@dons.net.au>
date Sun, 22 Jul 2018 12:56:29 +0930
parents 65be58857ed4 (current diff) 59cf68be7feb (diff)
children 718b963b0dfa
files vanlogger.py vanlogger.service
diffstat 4 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/99-giant-ips.rules	Sun Jul 22 12:56:29 2018 +0930
@@ -0,0 +1,2 @@
+ATTR{idVendor}=="0665", ATTR{idProduct}=="5161", MODE="660", GROUP="pi"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README	Sun Jul 22 12:56:29 2018 +0930
@@ -0,0 +1,6 @@
+sudo cp vanlogger.service /lib/systemd/system/
+sudo cp 99-giant-ips.rules /lib/udev/rules.d/
+sudo systemctl daemon-reload
+sudo udevadm control --reload
+sudo systemctl start vanllogger.service
+
--- 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)
--- a/vanlogger.service	Wed Mar 14 00:23:52 2018 +1030
+++ b/vanlogger.service	Sun Jul 22 12:56:29 2018 +0930
@@ -1,3 +1,4 @@
+# /lib/systemd/system/vanlogger.service
 [Unit]
 Description=Van logging
 
@@ -9,4 +10,5 @@
 Restart=on-failure
 
 [Install]
-WantedBy=multi-user.target
\ No newline at end of file
+WantedBy=multi-user.target
+