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'
|
SFTP_KEY = '/home/pi/.ssh/id_rsa'
|
||||||
|
|
||||||
|
|
||||||
DATA_FILE = './test.rrd'
|
DATA_FILE = './solar.rrd'
|
||||||
ARCHIVE_DATA_FILE = './test_archive.rrd'
|
ARCHIVE_DATA_FILE = './solar_archive.rrd'
|
||||||
DATA_INTERVAL = 60
|
DATA_INTERVAL = 60
|
||||||
ARCHIVE_INTERVAL = 60 * 60 * 24 # 1d
|
ARCHIVE_INTERVAL = 60 * 60 * 24 # 1d
|
||||||
ARCHIVE_KEEP_INTERVAL = 365 * 24 * 60 * 60 # 1 year
|
ARCHIVE_KEEP_INTERVAL = 365 * 24 * 60 * 60 # 1 year
|
||||||
|
@ -31,6 +31,7 @@ STORED_VALUES = [
|
||||||
StoredValue('load_switch', 0, 1),
|
StoredValue('load_switch', 0, 1),
|
||||||
StoredValue('max_charge_bat_day', 0.0, 1000.0),
|
StoredValue('max_charge_bat_day', 0.0, 1000.0),
|
||||||
StoredValue('max_charge_load_day', 0.0, 1000.0),
|
StoredValue('max_charge_load_day', 0.0, 1000.0),
|
||||||
|
StoredValue('SOC', 0.0, 1000.0)
|
||||||
]
|
]
|
||||||
|
|
||||||
GRAPHS = {
|
GRAPHS = {
|
||||||
|
@ -47,9 +48,12 @@ GRAPHS = {
|
||||||
GraphLine('load_switch', 'Relay', '#0000ff'),
|
GraphLine('load_switch', 'Relay', '#0000ff'),
|
||||||
],
|
],
|
||||||
'charges' : [
|
'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'),
|
GraphLine('max_charge_load_day', 'Max. Last Entladung [Ah]', '#ff0000'),
|
||||||
]
|
]
|
||||||
|
'soc' : [
|
||||||
|
GraphLine('soc', 'State Of Charge', '#ff0000'),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
FORMAT = ['Version',
|
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()
|
23
update.py
23
update.py
|
@ -62,16 +62,24 @@ def create_database():
|
||||||
def update_database(line):
|
def update_database(line):
|
||||||
update_values = []
|
update_values = []
|
||||||
for name, _, _ in STORED_VALUES:
|
for name, _, _ in STORED_VALUES:
|
||||||
if line[name] == None:
|
|
||||||
return
|
if line[name] != None:
|
||||||
update_values += ["%f" % float(line[name])]
|
update_values += ["%f" % float(line[name])]
|
||||||
|
else:
|
||||||
|
update_values += [""]
|
||||||
|
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
now = now - (now % DATA_INTERVAL)
|
now = now - (now % DATA_INTERVAL)
|
||||||
line = ("%d:" % now) + ":".join(update_values)
|
line = ("%d:" % now) + ":".join(update_values)
|
||||||
print(line)
|
|
||||||
|
try:
|
||||||
rrdtool.update(DATA_FILE, line)
|
rrdtool.update(DATA_FILE, line)
|
||||||
rrdtool.update(ARCHIVE_DATA_FILE, line)
|
rrdtool.update(ARCHIVE_DATA_FILE, line)
|
||||||
|
except rrdtool.OperationalError:
|
||||||
|
print("Failed updating files")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_graphs():
|
def update_graphs():
|
||||||
for graph_name, lines in GRAPHS.items():
|
for graph_name, lines in GRAPHS.items():
|
||||||
|
@ -128,16 +136,23 @@ def upload_graphs():
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ser = serial.Serial(SERIAL, BAUD_RATE, timeout=10.0)
|
ser = serial.Serial(SERIAL, BAUD_RATE, timeout=60.0)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = ser.readline().decode('ascii')
|
line = ser.readline().decode('ascii')
|
||||||
if len(line) > 0:
|
if len(line) > 0:
|
||||||
print(line)
|
print(line)
|
||||||
parsed = parse_line(line)
|
parsed = parse_line(line)
|
||||||
|
print(parsed)
|
||||||
update_database(parsed)
|
update_database(parsed)
|
||||||
update_graphs()
|
update_graphs()
|
||||||
upload_graphs()
|
upload_graphs()
|
||||||
|
else:
|
||||||
|
print("Timed out, supecting broken usb")
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue