PV Modul Growatt

Anfragen zum Erstellen von Modulen, Fragen zu Modulen
jonas1611
Beiträge: 17
Registriert: Do Jan 13, 2022 9:42 pm

Re: PV Modul Growatt

Beitrag von jonas1611 »

Hallo yankee,

ich habe zum Testen einen OpenWB Installation auf auf einen Pi4 gemacht, dazu läuft noch eine VZLogger Installation darauf.
Meine OpenWB Wallbox hat leider einen Passwortschutz...
Meintest du das so mit dem Logging? Bestimmt nicht... :lol:
Wo kann ich die Logdaten dann sehen?

Code: Alles auswählen

#!/usr/bin/env python3
#import logging
#import sys
#from typing import Iterable

import requests

from helpermodules.log import setup_logging_stdout
setup_logging_stdout()
from modules.common.component_state import InverterState
from modules.common.modbus import ModbusClient, ModbusDataType
from modules.common.store import get_inverter_value_store

def test():
    with ModbusClient("192.168.188.254") as client:
        power = client.read_holding_registers(30043, ModbusDataType.INT_16, unit=3)
    print(power)
    get_inverter_value_store(2).set(InverterState(power=-power))
Ach eine Datei /var/www/html/openWB/ramdisk/pv2 gibt es nicht, sollte aber bestimmt pv2watt sein
Die gibt es mit einem wert 0
yankee
Beiträge: 481
Registriert: Sa Mai 16, 2020 11:34 am

Re: PV Modul Growatt

Beitrag von yankee »

jonas1611 hat geschrieben: Mo Jan 17, 2022 10:19 pmMeintest du das so mit dem Logging? Bestimmt nicht... :lol:
Naja doch, schon so ungefähr. Was mir nur gerade so auffällt: Du musst die Funktion `test` natürlich auch aufrufen. Der typische Weg wäre in der Datei ganz unten zu ergänzen:

Code: Alles auswählen

if __name__ == '__main__':
    test()
jonas1611 hat geschrieben: Mo Jan 17, 2022 10:19 pmWo kann ich die Logdaten dann sehen?
Die bekommst du direkt auf den Bildschirm gespült.
jonas1611
Beiträge: 17
Registriert: Do Jan 13, 2022 9:42 pm

Re: PV Modul Growatt

Beitrag von jonas1611 »

Die bekommst du direkt auf den Bildschirm gespült.
Das heißt direkt am Bildschirm über HDMI? Muss ich wohl noch anbauen....

Also Tx und Rx blinken schon mal.... :D

Code: Alles auswählen

pi@raspberrypi:~ $ PYTHONPATH=/var/www/html/openWB/packages python3 /var/www/html/openWB/modules/wr2_smamodbus/sma.py
/usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
2022-01-17 23:45:02: PID: 3861: pymodbus.client.sync: Connection to Modbus server established. Socket ('192.168.188.80', 46909)
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: Current transaction state - IDLE
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: Running transaction 1
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x3 0x75 0x5b 0x0 0x1
2022-01-17 23:45:02: PID: 3861: pymodbus.client.sync: New Transaction state 'SENDING'
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: RECV: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x83 0x1
2022-01-17 23:45:02: PID: 3861: pymodbus.framer.socket_framer: Processing: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x83 0x1
2022-01-17 23:45:02: PID: 3861: pymodbus.factory: Factory Response[131]
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: Adding transaction 1
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: Getting transaction 1
2022-01-17 23:45:02: PID: 3861: pymodbus.transaction: Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Traceback (most recent call last):
  File "/var/www/html/openWB/packages/modules/common/modbus.py", line 81, in __read_registers
    raise FaultState.error(__name__+" "+str(response))
modules.common.fault_state.FaultState: ('modules.common.modbus Exception Response(131, 3, IllegalFunction)', <FaultStateLevel.ERROR: 2>)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/www/html/openWB/modules/wr2_smamodbus/sma.py", line 21, in <module>
    test()
  File "/var/www/html/openWB/modules/wr2_smamodbus/sma.py", line 16, in test
    power = client.read_holding_registers(30043, ModbusDataType.INT_16, unit=3)
  File "/var/www/html/openWB/packages/modules/common/modbus.py", line 115, in read_holding_registers
    self.delegate.read_holding_registers, address, types, byteorder, wordorder, **kwargs
  File "/var/www/html/openWB/packages/modules/common/modbus.py", line 97, in __read_registers
    str(e)) from e
modules.common.fault_state.FaultState: ("modules.common.modbus <class 'modules.common.fault_state.FaultState'> ('modules.common.modbus Exception Response(131, 3, IllegalFunction)', <FaultStateLevel.ERROR: 2>)", <FaultStateLevel.ERROR: 2>)
yankee
Beiträge: 481
Registriert: Sa Mai 16, 2020 11:34 am

Re: PV Modul Growatt

Beitrag von yankee »

jonas1611 hat geschrieben: Mo Jan 17, 2022 10:57 pm Die bekommst du direkt auf den Bildschirm gespült.
Das heißt direkt am Bildschirm über HDMI? Muss ich wohl noch anbauen....
Oder VGA oder DisplayPort oder... wie auch immer du sonst üblicherweise Text anzeigen lässt ;-).
jonas1611 hat geschrieben: Mo Jan 17, 2022 10:57 pmAlso Tx und Rx blinken schon mal.... :D
Ja prima. Und den log hast du auch gefunden.

Dann jetzt noch read_holding_registers durch read_input_registers austauschen.
jonas1611
Beiträge: 17
Registriert: Do Jan 13, 2022 9:42 pm

Re: PV Modul Growatt

Beitrag von jonas1611 »

Also für mich sieht das nicht viel anders aus.
Auch wird kein neuer Wert in die pv2watt eingetragen. Habe da mal eine 100 eingetragen, die bleibt da erst mal stehen....
Auch habe ich schon mal mit den Registern +1 -1 versucht.
Hier noch mal der neue Log

Code: Alles auswählen

pi@raspberrypi:~ $ PYTHONPATH=/var/www/html/openWB/packages python3 /var/www/html/openWB/modules/wr2_smamodbus/sma.py
/usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
2022-01-18 00:47:30: PID: 13968: pymodbus.client.sync: Connection to Modbus server established. Socket ('192.168.188.80', 36463)
2022-01-18 00:47:30: PID: 13968: pymodbus.transaction: Current transaction state - IDLE
2022-01-18 00:47:30: PID: 13968: pymodbus.transaction: Running transaction 1
2022-01-18 00:47:30: PID: 13968: pymodbus.transaction: SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x4 0x75 0x5b 0x0 0x1
2022-01-18 00:47:30: PID: 13968: pymodbus.client.sync: New Transaction state 'SENDING'
2022-01-18 00:47:30: PID: 13968: pymodbus.transaction: Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2022-01-18 00:47:31: PID: 13968: pymodbus.transaction: Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
2022-01-18 00:47:31: PID: 13968: pymodbus.transaction: RECV: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x84 0x1
2022-01-18 00:47:31: PID: 13968: pymodbus.framer.socket_framer: Processing: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x84 0x1
2022-01-18 00:47:31: PID: 13968: pymodbus.factory: Factory Response[132]
2022-01-18 00:47:31: PID: 13968: pymodbus.transaction: Adding transaction 1
2022-01-18 00:47:31: PID: 13968: pymodbus.transaction: Getting transaction 1
2022-01-18 00:47:31: PID: 13968: pymodbus.transaction: Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Traceback (most recent call last):
  File "/var/www/html/openWB/packages/modules/common/modbus.py", line 81, in __read_registers
    raise FaultState.error(__name__+" "+str(response))
modules.common.fault_state.FaultState: ('modules.common.modbus Exception Response(132, 4, IllegalFunction)', <FaultStateLevel.ERROR: 2>)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/var/www/html/openWB/modules/wr2_smamodbus/sma.py", line 22, in <module>
    test()
  File "/var/www/html/openWB/modules/wr2_smamodbus/sma.py", line 16, in test
    power = client.read_input_registers(30043, ModbusDataType.INT_16, unit=3)
  File "/var/www/html/openWB/packages/modules/common/modbus.py", line 134, in read_input_registers
    return self.__read_registers(self.delegate.read_input_registers, address, types, byteorder, wordorder, **kwargs)
  File "/var/www/html/openWB/packages/modules/common/modbus.py", line 97, in __read_registers
    str(e)) from e
modules.common.fault_state.FaultState: ("modules.common.modbus <class 'modules.common.fault_state.FaultState'> ('modules.common.modbus Exception Response(132, 4, IllegalFunction)', <FaultStateLevel.ERROR: 2>)", <FaultStateLevel.ERROR: 2>)
Hier noch die aktuelle sma.py

Code: Alles auswählen

#!/usr/bin/env python3
#import logging
#import sys
#from typing import Iterable

import requests

from helpermodules.log import setup_logging_stdout
#setup_logging_stdout()
from modules.common.component_state import InverterState
from modules.common.modbus import ModbusClient, ModbusDataType
from modules.common.store import get_inverter_value_store

def test():
    with ModbusClient("192.168.188.254") as client:
        power = client.read_input_registers(30043, ModbusDataType.INT_16, unit=3)
    print(power)
    get_inverter_value_store(2).set(InverterState(power=-power))

if __name__ == '__main__':
    setup_logging_stdout()
    test()
yankee
Beiträge: 481
Registriert: Sa Mai 16, 2020 11:34 am

Re: PV Modul Growatt

Beitrag von yankee »

Die Fehlermeldung sagt halt "IllegalFunction". Aber in deinem Screenshot auf der ersten Seite sieht es schon so aus als würdest du da erfolgreich input register liest...

Man sieht in dem Screenshot unten die Antwort vom Server als Binärdaten. Kann man da auch die Anfrage irgendwo sehen?
jonas1611
Beiträge: 17
Registriert: Do Jan 13, 2022 9:42 pm

Re: PV Modul Growatt

Beitrag von jonas1611 »

yankee hat geschrieben: Di Jan 18, 2022 10:10 pm Man sieht in dem Screenshot unten die Antwort vom Server als Binärdaten. Kann man da auch die Anfrage irgendwo sehen?
Ja auch im Bild zu sehen, aber wohl für das ganze Register.
Ich habe mal noch eine neue Abfrage (2 mal) erstellt für 30003

Code: Alles auswählen

[23:15:07] <= Response: 03 04 02 02 53 
[23:15:06] => Poll: 03 04 00 02 00 01 
[23:14:56] <= Response: 03 04 02 02 7D 
[23:14:55] => Poll: 03 04 00 02 00 01 
[23:14:55] Connect to TCP 192.168.188.254:502 timeout: 3
[23:14:52] Ready...
[23:14:52] Starting up...
Bild

Die Antworten im Modul SMA.py sind immer gleich...
pymodbus.transaction: RECV: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x84 0x1
Dateianhänge
Modbus_Growatt2.JPG
jonas1611
Beiträge: 17
Registriert: Do Jan 13, 2022 9:42 pm

Re: PV Modul Growatt

Beitrag von jonas1611 »

Ich habe auch die orginale sma.py so verändert das Antworten kommen, selbst da kommt:
RECV: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x84 0x1

Code: Alles auswählen

#!/usr/bin/python
import sys
# import os
# import time
# import getopt
# import socket
# import ConfigParser
import struct
# import binascii
from pymodbus.client.sync import ModbusTcpClient
from helpermodules.log import setup_logging_stdout
setup_logging_stdout()

ipaddress = ("192.168.188.254")

client = ModbusTcpClient(ipaddress, port=502)


# pv watt
resp= client.read_input_registers(30003,2,unit=3)
value1 = resp.registers[0]
value2 = resp.registers[1]
all = format(value1, '04x') + format(value2, '04x')
final = int(struct.unpack('>i', all.decode('hex'))[0])
if final < 0:
    final = 0
final = final * -1
f = open('/var/www/html/openWB/ramdisk/pv2watt', 'w')
f.write(str(final))
f.close()

Code: Alles auswählen

pi@raspberrypi:~ $ PYTHONPATH=/var/www/html/openWB/packages python3 /var/www/html/openWB/modules/wr2_smamodbus/sma.py
2022-01-18 23:43:11: PID: 25883: pymodbus.client.sync: Connection to Modbus server established. Socket ('192.168.188.80', 55969)
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: Current transaction state - IDLE
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: Running transaction 1
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x4 0x75 0x33 0x0 0x2
2022-01-18 23:43:11: PID: 25883: pymodbus.client.sync: New Transaction state 'SENDING'
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: RECV: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x84 0x1
2022-01-18 23:43:11: PID: 25883: pymodbus.framer.socket_framer: Processing: 0x0 0x1 0x0 0x0 0x0 0x3 0x3 0x84 0x1
2022-01-18 23:43:11: PID: 25883: pymodbus.factory: Factory Response[132]
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: Adding transaction 1
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: Getting transaction 1
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Traceback (most recent call last):
  File "/var/www/html/openWB/modules/wr2_smamodbus/sma.py", line 21, in <module>
    value1 = resp.registers[0]
AttributeError: 'ExceptionResponse' object has no attribute 'registers'
yankee
Beiträge: 481
Registriert: Sa Mai 16, 2020 11:34 am

Re: PV Modul Growatt

Beitrag von yankee »

jonas1611 hat geschrieben: Di Jan 18, 2022 10:27 pm Ich habe mal noch eine neue Abfrage (2 mal) erstellt für 30003

Code: Alles auswählen

[..]
[23:15:06] => Poll: 03 04 00 02 00 01
Mhh ok... In deinem log aus Python war es
2022-01-18 23:43:11: PID: 25883: pymodbus.transaction: SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x4 0x75 0x33 0x0 0x2
Function code ist zumindest gleich. Nur die Adresse unterscheidet sich (logischerweise).

Mach das doch nochmal mit der gleichen Adresse. Also auch die 30003 in Python. Und dann schauen ob das SEND hinten mit dem Poll aus deinem Programm identisch ist.

Edit: Mhh... ich sehe gerade noch... In Python fragt es Adresse 0x7533 (=30003) an. Das ist doch das Selbe. Und dann fragt es 2 Register an, die es lesen möchte. Bei deinem Programm, sofern ich denn die Ausgabe von deinem Programm denn überhaupt richtig interpretiere will es stattdessen nur einen Register lesen und zwar den Register 2. Also mal ganz doof: Was kommt denn in Python raus, wenn du es mit "client.read_input_registers(2, ModbusDataType.INT_16, unit=3)" versuchst?
jonas1611
Beiträge: 17
Registriert: Do Jan 13, 2022 9:42 pm

Re: PV Modul Growatt

Beitrag von jonas1611 »

Hallo yankee, wann schläfts du eigentlich :D
Also der Aufruf sieht jetzt so aus:
power = client.read_input_registers(2, ModbusDataType.INT_16, unit=3)
Hier das Ergenis:

Code: Alles auswählen

pi@raspberrypi:~ $ PYTHONPATH=/var/www/html/openWB/packages python3 /var/www/html/openWB/modules/wr2_smamodbus/sma.py
/usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
2022-01-19 11:00:38: PID: 5327: pymodbus.client.sync: Connection to Modbus server established. Socket ('192.168.188.80', 55961)
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: Current transaction state - IDLE
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: Running transaction 1
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x3 0x4 0x0 0x2 0x0 0x1
2022-01-19 11:00:38: PID: 5327: pymodbus.client.sync: New Transaction state 'SENDING'
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: RECV: 0x0 0x1 0x0 0x0 0x0 0x5 0x3 0x4 0x2 0x2 0x7f
2022-01-19 11:00:38: PID: 5327: pymodbus.framer.socket_framer: Processing: 0x0 0x1 0x0 0x0 0x0 0x5 0x3 0x4 0x2 0x2 0x7f
2022-01-19 11:00:38: PID: 5327: pymodbus.factory: Factory Response[ReadInputRegistersResponse: 4]
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: Adding transaction 1
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: Getting transaction 1
2022-01-19 11:00:38: PID: 5327: pymodbus.transaction: Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
2022-01-19 11:00:38: PID: 5327: pymodbus.payload: [639]
639
Traceback (most recent call last):
  File "/var/www/html/openWB/modules/wr2_smamodbus/sma.py", line 21, in <module>
    test()
  File "/var/www/html/openWB/modules/wr2_smamodbus/sma.py", line 17, in test
    get_inverter_value_store(2).set(InverterState(power=-power))
TypeError: __init__() missing 1 required positional argument: 'counter'
Antworten