Use HAProxy as Modbus-Proxy
I use the following HAProxy config to create a modbus proxy:
haproxy.cfg
global
daemon
maxconn 256
defaults
log global
mode tcp
option tcplog
option dontlognull
timeout connect 5000ms
timeout client 1000ms # Client inactivity on connection to HAProxy
timeout server 500ms # Server inactivity on connection from HAProxy to Inverter
retries 3
log stdout format raw local0 info
frontend modbus-frontend
bind *:5020
log 127.0.0.1 local0 debug
mode tcp
default_backend modbus-backend
backend modbus-backend
mode tcp
log 127.0.0.1 local1 debug
server server1 192.168.1.101:1502 maxconn 1 # This is the IP of the actual modbus device
balance leastconn
timeout queue 15000
docker-compose.yml
services:
haproxy:
image: haproxy:3.3
container_name: haproxy
ports:
- "5020:5020"
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
restart: unless-stopped