From 8ec76d309b2d5ef93059b809b6afefc8a4c0afed Mon Sep 17 00:00:00 2001 From: LKuemmel Date: Mon, 7 Aug 2023 15:19:11 +0200 Subject: [PATCH] configurable port for sungrow --- modules/bezug_sungrow/main.sh | 2 +- modules/speicher_sungrow/main.sh | 2 +- modules/wr_sungrow/main.sh | 2 +- packages/modules/devices/sungrow/config.py | 3 ++- packages/modules/devices/sungrow/device.py | 9 ++++++--- web/settings/modulconfigpv.php | 7 +++++++ 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/bezug_sungrow/main.sh b/modules/bezug_sungrow/main.sh index 9ee22c106..0cc745199 100755 --- a/modules/bezug_sungrow/main.sh +++ b/modules/bezug_sungrow/main.sh @@ -13,7 +13,7 @@ fi if [[ "$pvwattmodul" == "wr_sungrow" ]]; then echo "value read at pv modul" >/dev/null else - bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "counter" "$speicher1_ip" "$sungrowspeicherid" "$sungrowsr" >>"$MYLOGFILE" 2>&1 + bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "counter" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" "$sungrowsr" >>"$MYLOGFILE" 2>&1 ret=$? fi diff --git a/modules/speicher_sungrow/main.sh b/modules/speicher_sungrow/main.sh index a9a634c35..e73f14ff3 100755 --- a/modules/speicher_sungrow/main.sh +++ b/modules/speicher_sungrow/main.sh @@ -10,7 +10,7 @@ else MYLOGFILE="$RAMDISKDIR/bat.log" fi -bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "bat" "$speicher1_ip" "$sungrowspeicherid" >>"$MYLOGFILE" 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "bat" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" >>"$MYLOGFILE" 2>&1 ret=$? openwbDebugLog $DMOD 2 "BAT RET: $ret" diff --git a/modules/wr_sungrow/main.sh b/modules/wr_sungrow/main.sh index 17df513c1..597f84fff 100755 --- a/modules/wr_sungrow/main.sh +++ b/modules/wr_sungrow/main.sh @@ -15,6 +15,6 @@ if [[ "$wattbezugmodul" == "bezug_sungrow" ]]; then else read_counter=0 fi -bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$speicher1_ip" "$sungrowspeicherid" "1" "$read_counter" "$sungrowsr" >>"$MYLOGFILE" 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" "1" "$read_counter" "$sungrowsr" >>"$MYLOGFILE" 2>&1 cat "$RAMDISKDIR/pvwatt" diff --git a/packages/modules/devices/sungrow/config.py b/packages/modules/devices/sungrow/config.py index fd2268c0e..2fb6a668c 100644 --- a/packages/modules/devices/sungrow/config.py +++ b/packages/modules/devices/sungrow/config.py @@ -4,8 +4,9 @@ class SungrowConfiguration: - def __init__(self, ip_address: Optional[str] = None, modbus_id: int = 1): + def __init__(self, ip_address: Optional[str] = None, port: int = 502, modbus_id: int = 1): self.ip_address = ip_address + self.port = port self.modbus_id = modbus_id diff --git a/packages/modules/devices/sungrow/device.py b/packages/modules/devices/sungrow/device.py index fbc2089ea..f00c00d5d 100644 --- a/packages/modules/devices/sungrow/device.py +++ b/packages/modules/devices/sungrow/device.py @@ -31,7 +31,8 @@ def __init__(self, device_config: Union[Dict, Sungrow]) -> None: try: self.device_config = dataclass_from_dict(Sungrow, device_config) ip_address = self.device_config.configuration.ip_address - self.client = modbus.ModbusTcpClient_(ip_address, 502) + port = self.device_config.configuration.port + self.client = modbus.ModbusTcpClient_(ip_address, port) except Exception: log.exception("Fehler im Modul " + self.device_config.name) @@ -82,11 +83,12 @@ def update(self) -> None: def read_legacy(ip_address: str, + port: int, modbus_id: int, component_config: dict): device_config = Sungrow() device_config.configuration.ip_address = ip_address - device_config.configuration.port = 502 + device_config.configuration.port = port device_config.configuration.modbus_id = modbus_id dev = Device(device_config) dev.add_component(component_config) @@ -103,13 +105,14 @@ def read_legacy_counter(ip_address: str, modbus_id: int, version: int): def read_legacy_inverter(ip_address: str, + port: int, modbus_id: int, num: int, read_counter: int, version: int): device_config = Sungrow() device_config.configuration.ip_address = ip_address - device_config.configuration.port = 502 + device_config.configuration.port = port device_config.configuration.modbus_id = modbus_id dev = Device(device_config) dev.add_component(inverter.component_descriptor.configuration_factory(id=num)) diff --git a/web/settings/modulconfigpv.php b/web/settings/modulconfigpv.php index 584af4552..08e369234 100644 --- a/web/settings/modulconfigpv.php +++ b/web/settings/modulconfigpv.php @@ -202,6 +202,13 @@ +
+ +
+ + Hier kann ein abweichender Netzwerk-Port angegeben werden, auf dem die Modbus/TCP Verbindung aufgebaut wird.Standard ist 502. +
+