Mercurial > ~darius > hgwebdir.cgi > vanlogger
changeset 22:59cf68be7feb
add trivial README
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sun, 22 Jul 2018 12:54:05 +0930 |
parents | 3f22fa1f32d5 |
children | efe1954da8ca |
files | 99-giant-ips.rules README vanlogger.py vanlogger.service |
diffstat | 4 files changed, 25 insertions(+), 3 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:54:05 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:54:05 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 Fri Dec 22 16:30:45 2017 +0100 +++ b/vanlogger.py Sun Jul 22 12:54:05 2018 +0930 @@ -8,6 +8,7 @@ import giant.giant as giant import serial import sqlite3 +import sys def create(cur): cur.execute(''' @@ -169,23 +170,33 @@ 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/ttyUSB0', 2400, parity='E') + s = serial.Serial('/dev/ttyS0', 2400, parity='E') 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 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 Fri Dec 22 16:30:45 2017 +0100 +++ b/vanlogger.service Sun Jul 22 12:54:05 2018 +0930 @@ -1,12 +1,14 @@ +# /lib/systemd/system/vanlogger.service [Unit] Description=Van logging [Service] User=pi Group=pi -Type=forking -ExecStart=/usr/bin/tmux new-session -s vanlogger -d /home/pi/vanlogger/vanlogger.py +Type=simple +ExecStart=/home/pi/vanlogger/vanlogger.py Restart=on-failure [Install] WantedBy=multi-user.target +