First of all: thanks for this project. It's really useful for me!
I successfully use modbus-mqtt in a project to read a single energy meter via TCP. This works fine.
I'm now evaluating whether modbus-mqtt can be used for a different project where multiple energy meters have to be read via RTU.
Current setup
I managed to read a single energy meter via RTU using the following configuration:
{
"proto": "rtu",
"tty": "/dev/ttyUSB0",
"baud_rate": 19200,
"unit": 30,
"registers": [
{ "name": "firmware", "address": 1, "register_type": "holding", "scale": -1, "interval": "100y" },
{ "name": "energy", "address": 28, "register_type": "holding", "type": "u32", "scale": -2, "interval": "30s" },
{ "name": "power", "address": 38, "register_type": "holding", "scale": -2, "interval": "30s" }
]
}
This works fine, too. Now I'd like to add a second energy meter that is connected to the same bus. The second meter has the same model as the first one, only the unit (slave id) differs. My project includes 15 meters in total.
When I read the documentation right, modbus-mqtt supports a 1:1 relation between connection and unit. Is that correct? If so, the serial connection would have to be declared for each energy meter. I'm concerned about problems when requests for multiple units are written to the serial device without coordination.
Suggestion: Multiple units per connection
Would it be possible to allow a 1:n relation between connection and units? For example:
{
"proto": "rtu",
"tty": "/dev/ttyUSB0",
"baud_rate": 19200,
"units": [
{
"unit": 30,
"registers": [
{ "name": "firmware", "address": 1, "register_type": "holding", "scale": -1, "interval": "100y" },
{ "name": "energy", "address": 28, "register_type": "holding", "type": "u32", "scale": -2, "interval": "30s" },
{ "name": "power", "address": 38, "register_type": "holding", "scale": -2, "interval": "30s" }
]
}
{
"unit": 31,
"registers": [
{ "name": "firmware", "address": 1, "register_type": "holding", "scale": -1, "interval": "100y" },
{ "name": "energy", "address": 28, "register_type": "holding", "type": "u32", "scale": -2, "interval": "30s" },
{ "name": "power", "address": 38, "register_type": "holding", "scale": -2, "interval": "30s" }
]
}
]
}
With such a feature I'd be able to implement my project with modbus-mqtt. Without it, I'll probably need to look for an alternative, which I'd like to avoid.
Optional feature: Unit templates
When multiple counters of the same model are connected, their declaration would introduce redundancy. This could be avoided by a template mechanism, e.g.:
{
"proto": "rtu",
"tty": "/dev/ttyUSB0",
"baud_rate": 19200,
"unit_templates": {
"foo": {
"address_offset": -1,
"register_type": "holding",
"registers": [
{ "name": "firmware", "address": 1, "scale": -1, "interval": "100y" }
]
}
},
"units": [
{ "unit": 30, "template": "foo" },
{ "unit": 31, "template": "foo" }
]
}
Such a the template mechanism would be nice to have, but is not required to complete my project.
Unfortunately, I have no experience in Rust so I can't supply a pull request. When there's a chance to implement this feature, I'm ready to help.