Added archive graphs and ssh upload

This commit is contained in:
Sebastian 2018-10-13 14:07:07 +02:00
parent fa600586ae
commit 999a24c632
4 changed files with 55 additions and 9 deletions

View File

@ -7,10 +7,16 @@ BAUD_RATE = 4800
STOP_BITS = 1
PARITY = None
SFTP_HOST = 'rc-club-albersweiler.de'
SFTP_PORT = 22
SFTP_USER = 'sftprcclub'
SFTP_KEY = '/home/sebastian/.ssh/id_rsa'
DATA_FILE = './test.rrd'
ARCHIVE_DATA_FILE = './test_archive.rrd'
DATA_INTERVAL = 60
ARCHIVE_INTERVAL = 60 * 60 # 1h
ARCHIVE_INTERVAL = 60 * 60 * 24 # 1d
ARCHIVE_KEEP_INTERVAL = 365 * 24 * 60 * 60 # 1 year
MAX_MISSING = 0.5
@ -30,19 +36,19 @@ STORED_VALUES = [
]
GRAPHS = {
'voltages.png' : [
'voltages' : [
GraphLine('U_bat', 'Spannung Batterie [V]', '#ff0000'),
GraphLine('U_mod1', 'Spannung Modul 1 [V]', '#00ff00'),
GraphLine('U_mod2', 'Spannung Modul 2 [V]', '#0000ff'),
],
'currents.png' : [
'currents' : [
GraphLine('I_pv_in', 'Strom PV [A]', '#ff0000'),
GraphLine('I_load_total', 'Strom Last [A]', '#00ff00'),
],
'realy.png' : [
'realy' : [
GraphLine('load_switch', 'Relay', '#0000ff'),
],
'charges.png' : [
'charges' : [
GraphLine('max_charge_bat_day', 'Max. Batterie Landung [Ah]', '#0000ff'),
GraphLine('max_charge_load_day', 'Max. Last Entladung [Ah]', '#ff0000'),
]

View File

@ -6,7 +6,7 @@ from time import sleep
from config import *
from update import parse_line, create_database, update_database, update_graphs
from update import parse_line, create_database, update_database, update_graphs, upload_graphs
calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
@ -41,6 +41,7 @@ def main():
parsed = parse_line(line)
update_database(parsed)
update_graphs()
upload_graphs()
sleep(60)
if __name__ == '__main__':

13
requirements.txt Normal file
View File

@ -0,0 +1,13 @@
asn1crypto==0.24.0
bcrypt==3.1.4
cffi==1.11.5
crcmod==1.7
cryptography==2.3.1
idna==2.7
paramiko==2.4.2
pyasn1==0.4.4
pycparser==2.19
PyNaCl==1.3.0
pyserial==3.4
rrdtool==0.1.14
six==1.11.0

View File

@ -1,8 +1,10 @@
#!/usr/bin/env python3
import sys
import time
import serial
import crcmod
import rrdtool
import paramiko
from config import *
@ -50,8 +52,6 @@ def create_database():
rows = ARCHIVE_KEEP_INTERVAL / ARCHIVE_INTERVAL
rrd_archive_params += sources
rrd_archive_params += ["RRA:AVERAGE:%f:%d:%d" % (MAX_MISSING, steps, rows)]
rrd_archive_params += ["RRA:MAX:%f:%d:%d" % (MAX_MISSING, steps, rows)]
rrd_archive_params += ["RRA:MIN:%f:%d:%d" % (MAX_MISSING, steps, rows)]
rrdtool.create(*rrd_archive_params)
@ -70,15 +70,41 @@ def update_database(line):
def update_graphs():
for name, lines in GRAPHS.items():
graph_params = [name, '-a', 'PNG', '-s', 'n-%d' % ARCHIVE_INTERVAL]
# Render current data
graph_params = ['%s.png' % name, '-a', 'PNG', '-s', 'n-%d' % ARCHIVE_INTERVAL]
for name, lable, color in lines:
graph_params += ['DEF:%s=%s:%s:LAST' % (name, DATA_FILE, name)]
graph_params += ['LINE1:%s%s:%s' % (name, color, lable)]
rrdtool.graph(*graph_params)
# Also render Archives
graph_params = ['%s_archive.png' % name, '-a', 'PNG', '-s', 'n-%d' % ARCHIVE_KEEP_INTERVAL]
for name, lable, color in lines:
graph_params += ['DEF:%s=%s:%s:AVERAGE' % (name, DATA_FILE, name)]
graph_params += ['LINE1:%s%s:%s' % (name, color, lable)]
rrdtool.graph(*graph_params)
def upload_graphs():
try:
key = paramiko.RSAKey.from_private_key_file(SFTP_KEY)
transport = paramiko.Transport((SFTP_HOST, SFTP_PORT))
transport.connect()
transport.auth_publickey(SFTP_USER, key)
sftp = paramiko.SFTPClient.from_transport(transport)
for name, _ in GRAPHS.items():
sftp.put('%s.png' % name, 'solar/%s.png' % name)
sftp.put('%s_archive.png' % name, 'solar/%s_archive.png' % name)
sftp.close()
transport.close()
except:
print("Unexpected error uploading:", sys.exc_info()[1])
def main():
pass