- Registriert
- Feb. 2008
- Beiträge
- 1.606
Jetzt steh ich auch auf´m Schlauch 🤦‍♂️
Das ist dein Anfang vom Codebereich.
Dort muss ich das hier reinkopieren:
Sry, ich checks nicht und dann aus print payload machen ?
Das ist dein Anfang vom Codebereich.
Dort muss ich das hier reinkopieren:
Code:
#!/usr/bin/env python3
# coding=utf-8
"""
*
* by Wenger Florian 2015-09-02
* wenger@unifox.at
*
* endless loop (until ctrl+c) displays measurement from SMA Energymeter
*
*
* this software is released under GNU General Public License, version 2.
* This program is free software;
* you can redistribute it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* 2018-12-22 Tommi2Day small enhancements
* 2019-08-13 datenschuft run without config
* 2020-01-04 datenschuft changes to tun with speedwiredecoder
*
*/
"""
import signal
import sys
#import smaem
import socket
import struct
from configparser import ConfigParser
from speedwiredecoder import *
# clean exit
def abortprogram(signal,frame):
# Housekeeping -> nothing to cleanup
print('STRG + C = end program')
sys.exit(0)
# abort-signal
signal.signal(signal.SIGINT, abortprogram)
#read configuration
parser = ConfigParser()
#default values
smaserials = ""
ipbind = '0.0.0.0'
MCAST_GRP = '239.12.255.254'
MCAST_PORT = 9522
parser.read(['/etc/smaemd/config','config'])
try:
smaemserials=parser.get('SMA-EM', 'serials')
ipbind=parser.get('DAEMON', 'ipbind')
MCAST_GRP = parser.get('DAEMON', 'mcastgrp')
MCAST_PORT = int(parser.get('DAEMON', 'mcastport'))
except:
print('Cannot find config /etc/smaemd/config... using defaults')
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', MCAST_PORT))
try:
mreq = struct.pack("4s4s", socket.inet_aton(MCAST_GRP), socket.inet_aton(ipbind))
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
except BaseException:
print('could not connect to mulicast group or bind to given interface')
sys.exit(1)
# processing received messages
while True:
emparts = {}
emparts=decode_speedwire(sock.recv(608))
# Output...
# don't know what P,Q and S means:
# http://en.wikipedia.org/wiki/AC_power or http://de.wikipedia.org/wiki/Scheinleistung
# thd = Total_Harmonic_Distortion http://de.wikipedia.org/wiki/Total_Harmonic_Distortion
# cos phi is always positive, no matter what quadrant
print ('\n')
print ('SMA-EM Serial:{}'.format(emparts['serial']))
print ('-------Gesamt-------')
print ('P: Verbrauch: {}W Einspeisung: {}W '.format(emparts['pconsume'],emparts['psupply']))
print ('S: Verbrauch: {}VA Einspeisung: {}VA '.format(emparts['sconsume'],emparts['ssupply']))
print ('Q: induktiv: {}var kapazitiv: {}var '.format(emparts['qconsume'],emparts['qsupply']))
print ('cos phi: {}°'.format(emparts['cosphi']))
print ('Frequenz: {}Hz'.format(emparts['frequency']))
print ('-------L1-------')
print ('P: Verbrauch: {}W Einspeisung: {}W '.format(emparts['p1consume'],emparts['p1supply']))
print ('S: Verbrauch: {}VA Einspeisung: {}VA '.format(emparts['s1consume'],emparts['s1supply']))
print ('Q: ind: {}var kap: {}var '.format(emparts['q1consume'],emparts['q1supply']))
print ('U: {}V I: {}A cos phi: {}°'.format(emparts['u1'],emparts['i1'],emparts['cosphi1']))
print ('-------L2-------')
print ('P: Verbrauch: {}W Einspeisung: {}W '.format(emparts['p2consume'],emparts['p2supply']))
print ('S: Verbrauch: {}VA Einspeisung: {}VA '.format(emparts['s2consume'],emparts['s2supply']))
print ('Q: ind: {}var kap: {}var '.format(emparts['q2consume'],emparts['q2supply']))
print ('U: {}V I: {}A cos phi:{}°'.format(emparts['u2'],emparts['i2'],emparts['cosphi2']))
print ('-------L3-------')
print ('P: Verbrauch: {}W Einspeisung: {}W '.format(emparts['p3consume'],emparts['p3supply']))
print ('S: Verbrauch: {}VA Einspeisung: {}VA '.format(emparts['s3consume'],emparts['s3supply']))
print ('Q: ind: {}var kap: {}var '.format(emparts['q3consume'],emparts['q3supply']))
print ('U: {}V I: {}A cos phi: {}°'.format(emparts['u3'],emparts['i3'],emparts['cosphi3']))
print ('Version: {}'.format(emparts['speedwire-version']))
Sry, ich checks nicht und dann aus print payload machen ?