Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable port for sungrow #2774

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading