Skip to content

Added Modbus TCP proxy - #99

Merged
githubDante merged 4 commits into
jmccrohan:mainfrom
andrei-lazarov:tcp_proxy
Oct 30, 2025
Merged

githubDante merged 4 commits into
jmccrohan:mainfrom
andrei-lazarov:tcp_proxy

Conversation

@andrei-lazarov

Copy link
Copy Markdown
Contributor

Related to #98

Hello! I needed proper TCP frames for systems that don't support the 'RTU over TCP' messages provided by solarman_rtu_proxy.py.

So I added the solarman_tcp_proxy.py utility.

It works pretty well.

I do get errors sometimes (on both proxies), but it's probably a bad connection..
I am connected remotely through port forwarding.

ERROR: request ask for transaction_id=31 but got id=28, Skipping
ERROR: request ask for transaction_id=31 but got id=29, Skipping

Would love to hear some feedback.

@githubDante

Copy link
Copy Markdown
Collaborator

Hi,

We have umodbus as a dependency and I think it is better to use the CRC methods from there

from umodbus.client.serial.redundancy_check import get_crc

Also do not use the UnitId as SlaveId they are not the same. It will work if you use 1 which is the default for most inverters, but will fail with any other value. If the proxy must service more than one inverter the UnitId must be mapped to the correct PysolarmanV5 instance.

@andrei-lazarov

andrei-lazarov commented Oct 28, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks!
I changed it to use the provided crc method.

Well the proxy requires IP and serial from the inverter, so it can only serve one, right?
You mean - if I connect multiple inverters, through multiple proxies, to HA for example - each will get a different UnitId from HA: 1, 2, 3..
So should I hard-code the SlaveId to 1 like in did in the last commit?

Comment thread utils/solarman_tcp_proxy.py Outdated
@githubDante

Copy link
Copy Markdown
Collaborator

You mean - if I connect multiple inverters, through multiple proxies, to HA for example - each will get a different UnitId from HA: 1, 2, 3..
So should I hard-code the SlaveId to 1 like in did in the last commit?

I don't use HA, so I can't comment on that, but you can have a map/dict even in this state of the proxy and to instantiate different client for different unitId. The slaveId for all however should be 1.
We use it (0x1) as a default value (see the PysolamanV5.__init__/mb_slave_id) but the modbus frame stays untouched by the send_raw_modbus_frame method, so the slaveId should already be there.

@andrei-lazarov

Copy link
Copy Markdown
Contributor Author

Thanks. Fixed, the tests pass now

@githubDante

Copy link
Copy Markdown
Collaborator

I see. Thank you!

@githubDante
githubDante merged commit f75cee3 into jmccrohan:main Oct 30, 2025
2 checks passed
@andrei-lazarov
andrei-lazarov deleted the tcp_proxy branch October 30, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants