Skip to content

Commit

Permalink
configurable port for sungrow
Browse files Browse the repository at this point in the history
  • Loading branch information
LKuemmel committed Aug 7, 2023
1 parent e4b372b commit 8ec76d3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/bezug_sungrow/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion modules/speicher_sungrow/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion modules/wr_sungrow/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion packages/modules/devices/sungrow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
9 changes: 6 additions & 3 deletions packages/modules/devices/sungrow/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions web/settings/modulconfigpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@
</div>
</div>
</div>
<div class="form-row mb-1">
<label for="sungrowspeicherport" class="col-md-4 col-form-label">Netzwerk-Port</label>
<div class="col">
<input class="form-control" type="number" min="1" step="1" name="sungrowspeicherport" id="sungrowspeicherport" value="<?php echo $sungrowspeicherportold ?>">
<span class="form-text small">Hier kann ein abweichender Netzwerk-Port angegeben werden, auf dem die Modbus/TCP Verbindung aufgebaut wird.Standard ist 502.</span>
</div>
</div>
<div class="form-row mb-1">
<label for="sungrowspeicherid" class="col-md-4 col-form-label">Geräteadresse</label>
<div class="col">
Expand Down

0 comments on commit 8ec76d3

Please sign in to comment.