Added fixes from pi
This commit is contained in:
parent
d16c1b5e91
commit
44d8d4cda7
10
config.py
10
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',
|
||||
|
|
|
@ -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()
|
27
update.py
27
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()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue