Samstag, 8. Mai 2021

Building a RS485-Ethernet-Modbus-tunnel

 The plan sounds simple: install solar panels and an inverter in the garage, and enjoy the sun delivering power for the house. But how to do this if 1. the garage is 50m away from the house and the only connection is a 5 wire power cord and an ethernet connection and 2. no power should be fed back into the outside power network. The latter requires a measurement device at the main power and a connection between this device and the inverter. Typically, these devices are connected via an RS485 connection, and the SDM630 meter that I am trying to connected uses the Modbus protocol. So, one possible solution to the problem of connecting the inverter to the powermeter is to use 2 wires of the ethernet cable for a direct connection. But that means to drop gigabit support, because for a gigabit connection all wire pairs are actually used. Also, it is not very elegant to hack the cable to split a wire pair from the rest.

So, what would be a more elegant solution? There are commercial RS485-to-ethernet bridges that are advertised for exactly this scenario. But they are really expensive. And there are cheap RS485-/Modbus-to-Ethernet bridges, f.e. the USR-DR302. They support many modes and I was hoping that it is possible to use them for a simply RS485/Modbus tunnel. Interestingly, I could not find a single article about such a setup, and the manual is no big help either. So I tried, using an ESP32 with a RS485 shield simulating a measuring device, and a computer with an RS485-USB adapter simulating the inverter. First, I connected the devices directly, then I tried to put the DR302 devices as tunneling devices in between. To do this, the DR302 which is connected to the meter is running in "TCP server" mode, while the DR302 connected to the computer is running in "TCP client mode", connecting to the IP address and port of the TCP server. Also, I selected  the "Modbus TCP" to use modbus TCP as an intermediate protocol. First try, switch on, and: success! This setup works exactly as hoped!

Keine Kommentare:

Kommentar veröffentlichen