[:de]In unserer Photovoltaik-Anlage ist ein Wechselrichter von SMA verbaut, der das Modbus-Protokoll zur Abfrage von Anlagenparametern zur Verfügung stellt.
SMA stellt für dieses Gerät (und andere Geräte mit Modbus) Tabellen zur Verfügung, wo man ablesen kann, an welcher Adresse welche Information zur Verfügung steht.
Für Python gibt es die Modbusbibliothek ‚pymodbus‘.
Mit etwas Tüftelei habe ich eine Python Applikation erstellt, die entweder über ein grafisches Interface bedient werden kann, oder auch von der Befehlszeile (ohne grafische Oberfläche) gestartet werden kann.
Die Applikation kann dann in der grafischen Oberfläche mehrere Momentanwerte darstellen oder auf der Befehlszeile immer einen Wert direkt abrufen.
Außerdem kann man eine Log-Datei angeben, in die man dann in einstellbaren Intervallen die Werte abrufen und in ebenfalls einstellbarem Intervall regelmäßig auf einen Datenträger abspeichern kann.
Für Langzeitüberwachung habe ich dann noch einen Raspberry-Pi 3 unter Raspbian ins Netzwerk eingebunden, wo die Applikation dann regelmäßig dauerhaft die Daten vom Wechselrichter einsammelt. Der Raspberry hängt lediglich an einem 5 V Netzteil, und wird nur übers WLAN administriert.
Unter Raspbian brauchte ich dann noch ein paar Vorarbeiten:
- die WLAN-Verbindung als Standardverbindung einstellen und automatisch verbinden lassen.
- das Paket python-dev installieren (aptitude install python-dev)
- das Python-Paket pymodbus installieren (sudo pip install pymodbus)
- das Python-Paket docopt installieren (sudo pip install docopt)
Danach lässt sich das Skript ganz einfach mit „python pymodmon.py -i Configfile.ini“ starten.
Die Konfigurationsdatei lässt sich ganz einfach erzeugen indem man zuerst mit „python pymodmon.py“ im grafischem Modus startet und die gewünschten Adressen ergänzt. Diese kann man dann auch gleich testen, ob sie abgefragt werden können. Wenn alle Einstellungen wie gewünscht erstellt sind, kann man die Konfigurationsdatei speichern und dann im Kommandozeilenmodus direkt nutzen.
In der Konfigurationsdatei kann man auch die gewünschte Log-Datei angeben. Wenn diese noch nicht existiert, wird sie erstellt. Wenn sie schon existiert, werden einfach die neuen Daten an der Datei angefügt.
Zu finden ist das Python-Skript unter github.com: https://github.com/transistorgrab/PyModMon
Die Programmoberfläche ist komplett auf englisch gehalten, sollte aber trotzdem auch mit wenig Englischkenntnissen bedienbar sein.
[:en]Our Photovoltaik installation is powered by a SMA solar inverter, which provides the Modbus protocol for monitoring installation parameters.
SMA provides for this device (and other devices with Modbus) tables with information at which address which information resides.
For Python there is the Modbus library ‚pymodbus‘.
With some tinkering I made a Python application, which can be used with a graphical interface or via command line (without graphical interface).
The application can display multiple current values in the graphical interface or via the command line a single value directly.
Also you can specify a log file where values can be stored in configurable intervals and configurable save interval to disk.
For long time monitoring I configured a Raspberry-Pi 3 with Raspbian to run in my network. The Raspberry collects then regularly data from the inverter. The Raspberry is only supplied by a 5 V power supply and is administred via WLAN.
For Raspbian I needed just a few preparations:
- configure WLAN connection as default connection and automatic connection
- install the Raspbian package python-dev (sudo aptitude install python-dev)
- install the Python package pymodbus (sudo pip install pymodbus)
- install the Python package docopt (sudo pip install docopt)
After this the script can be run with „python pymodmon.py -i Configfile.ini“.
The config file can be easily generated by running the skript in the graphical mode via „python pymodmon.py“ in a xterm and then adding the desired addresses and settings. In the graphical mode can then be tested if the addresses are available. When all settings are set as desired the config file can be saved and is then usable in the command line mode.
The config file also allows for setting the log file. If this does not exist it will be generated. If it exists new data will be appended to it.
You can find the python script on github.com: https://github.com/transistorgrab/PyModMon
Vielen Dank für das Script!
Ich kann leider kein Python und habe daher Probleme bei der Fehlersuche. Was habe ich falsch gemacht?
—– Beginn —–
python pymodmon.py –ip=wechselrichter.intern.nemox.net –port=502 –id=3 –addr=30775 –type=S32 –format=RAW
Traceback (most recent call last):
File „pymodmon.py“, line 971, in
inout.runCommunication()
File „pymodmon.py“, line 313, in runCommunication
self.pollTargetData()
File „pymodmon.py“, line 353, in pollTargetData
message = BinaryPayloadDecoder.fromRegisters(received.registers, byteorder=Endian.Big, wordorder=Endian.Big)
AttributeError: ‚NoneType‘ object has no attribute ‚registers‘
PyModMon has exited cleanly.
—– Ende —–
Gibt es eine Möglichkeit per Bitcoin oder PayPal etwas zu spenden?
Hallo Rudolf,
die Fehlermeldung weißt darauf hin, dass die installierte pymodbus-Version nicht zur Version des Skriptes passt.
Einfach noch einmal kontrollieren ob du die aktuelle Version des Skriptes von Github geladen hast.