From 44d8d4cda70b7e5cc9215f9c4ec21b8ba9273488 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Wed, 7 Nov 2018 19:07:07 +0100 Subject: [PATCH] Added fixes from pi --- config.py | 10 +++++++--- crc_test.py | 13 +++++++++++++ update.py | 27 +++++++++++++++++++++------ 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 crc_test.py diff --git a/config.py b/config.py index 26864b4..9aec366 100644 --- a/config.py +++ b/config.py @@ -11,8 +11,8 @@ SFTP_USER = 'sftprcclub' SFTP_KEY = '/home/pi/.ssh/id_rsa' -DATA_FILE = './test.rrd' -ARCHIVE_DATA_FILE = './test_archive.rrd' +DATA_FILE = './solar.rrd' +ARCHIVE_DATA_FILE = './solar_archive.rrd' DATA_INTERVAL = 60 ARCHIVE_INTERVAL = 60 * 60 * 24 # 1d ARCHIVE_KEEP_INTERVAL = 365 * 24 * 60 * 60 # 1 year @@ -31,6 +31,7 @@ STORED_VALUES = [ StoredValue('load_switch', 0, 1), StoredValue('max_charge_bat_day', 0.0, 1000.0), StoredValue('max_charge_load_day', 0.0, 1000.0), + StoredValue('SOC', 0.0, 1000.0) ] GRAPHS = { @@ -47,9 +48,12 @@ GRAPHS = { GraphLine('load_switch', 'Relay', '#0000ff'), ], 'charges' : [ - GraphLine('max_charge_bat_day', 'Max. Batterie Landung [Ah]', '#0000ff'), + GraphLine('max_charge_bat_day', 'Max. Batterie Ladung [Ah]', '#0000ff'), GraphLine('max_charge_load_day', 'Max. Last Entladung [Ah]', '#ff0000'), ] + 'soc' : [ + GraphLine('soc', 'State Of Charge', '#ff0000'), + ] } FORMAT = ['Version', diff --git a/crc_test.py b/crc_test.py new file mode 100644 index 0000000..14af90c --- /dev/null +++ b/crc_test.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + + +from update import * + + +def main(): + line = b'1;2018/10/20;18:16;12.9;1.1;#;95.0;#;-1.2;#;#;0.0;0.0;1.2;1.2;16.0;1;F;1;0;0;19;4665;21;3288;0;E307\r\n' + + parse_line(line.decode('ascii')) + +if __name__ == '__main__': + main() diff --git a/update.py b/update.py index be32846..5515162 100644 --- a/update.py +++ b/update.py @@ -62,16 +62,24 @@ def create_database(): def update_database(line): update_values = [] for name, _, _ in STORED_VALUES: - if line[name] == None: - return + + if line[name] != None: update_values += ["%f" % float(line[name])] + else: + update_values += [""] + now = time.time() now = now - (now % DATA_INTERVAL) line = ("%d:" % now) + ":".join(update_values) - print(line) - rrdtool.update(DATA_FILE, line) - rrdtool.update(ARCHIVE_DATA_FILE, line) + + try: + rrdtool.update(DATA_FILE, line) + rrdtool.update(ARCHIVE_DATA_FILE, line) + except rrdtool.OperationalError: + print("Failed updating files") + + def update_graphs(): for graph_name, lines in GRAPHS.items(): @@ -128,16 +136,23 @@ def upload_graphs(): def main(): - ser = serial.Serial(SERIAL, BAUD_RATE, timeout=10.0) + ser = serial.Serial(SERIAL, BAUD_RATE, timeout=60.0) while True: line = ser.readline().decode('ascii') if len(line) > 0: print(line) parsed = parse_line(line) + print(parsed) update_database(parsed) update_graphs() upload_graphs() + else: + print("Timed out, supecting broken usb") + sys.stdout.flush() + sys.exit(-1) + + sys.stdout.flush()