tiagocoutinho/modbus-proxy-py
Bridge between your modbus device(s) and multiple concurrent clients (python server)
4.5K
Many modbus devices support only one or very few clients. This proxy acts as a bridge between the client and the modbus device. It can be seen as a layer 7 reverse proxy. This allows multiple clients to communicate with the same modbus device.
When multiple clients are connected, cross messages are avoided by serializing communication on a first come first served REQ/REP basis.
To bridge a single modbus device without needing a configuration file is straight forward:
$ docker run -d -p 5020:502 tiagocoutinho/modbus-proxy-py -b tcp://0:502 --modbus tcp://plc1.acme.org:502
Now you should be able to access your modbus device through the modbus-proxy by connecting your client(s) to <your-hostname/ip>:5020
.
If, instead, you want to use a configuration file, you must mount the file so it is visible by the container.
Assuming you have prepared a conf.yml
in the current directory:
devices:
- modbus:
url: plc1.acme.org:502
listen:
bind: 0:502
Here is an example of how to run the container:
docker run -p 5020:502 -v $PWD/conf.yml:/config/modbus-proxy.yml tiagocoutinho/modbus-proxy-py
By default the Dockerfile will run modbus-proxy -c /config/modbus-proxy.yml
so if your mounting that volume you don't need to pass any arguments.
Note that for each modbus device you add in the configuration file you need to publish the corresponding bind port on the host
(-p <host port>:<container port>
argument).
Logging configuration can be added to the configuration file by adding a new logging
keyword.
The logging configuration will be passed to logging.config.dictConfig() so the file contents must obey the Configuration dictionary schema.
Here is a YAML example:
devices:
- modbus:
url: plc1.acme.org:502
listen:
bind: 0:9000
logging:
version: 1
formatters:
standard:
format: "%(asctime)s %(levelname)8s %(name)s: %(message)s"
handlers:
console:
class: logging.StreamHandler
formatter: standard
root:
handlers: ['console']
level: DEBUG
docker pull tiagocoutinho/modbus-proxy-py