Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Modbus terminal Monitoring #7523

Closed
binueda opened this issue May 15, 2020 · 18 comments · Fixed by #9279
Closed

Multiple Modbus terminal Monitoring #7523

binueda opened this issue May 15, 2020 · 18 comments · Fixed by #9279
Labels
area/modbus feature request Requests for new plugin and for new features to existing plugins help wanted Request for community participation, code, contribution

Comments

@binueda
Copy link

binueda commented May 15, 2020

Feature Request

Need a configuration option to add more than one Modbus slave terminal

Proposal: Not sure how

Current behavior: only one Modbus slave can be configured using telegraf

Desired behavior: Should be able to monitor multiple slaves

Use case:

There are instances where more than one device on the network which need to be monitored.

@ssoroka
Copy link
Contributor

ssoroka commented May 15, 2020

You should be able to put multiple [[inputs.modbus]] sections, and each one can monitor a different terminal

@danielnelson
Copy link
Contributor

Here is the related issue on the Community site: https://community.influxdata.com/t/telegraf-requesting-from-multiple-modbus-slaves

If you need to use multiple slave IDs for a single connection you must use multiple plugin definitions, but for devices connected over USB, it is problematic to make concurrent requests.

@danielnelson danielnelson added area/modbus feature request Requests for new plugin and for new features to existing plugins labels May 15, 2020
@danielnelson
Copy link
Contributor

cc @garciaolais

@garciaolais
Copy link
Contributor

Hello @binueda

as @ssoroka mentioned, you can use multiple [[inputs.modbus]]

Multiple

@ssoroka ssoroka closed this as completed May 15, 2020
@danielnelson
Copy link
Contributor

I said the same thing originally ;). This won't work though if you are connecting over the same USB link. From the community site:

To me it seems like they are running in parallel and trying to access controller = “file:///dev/ttyUSB0” at the same time, giving: [inputs.modbus] Error in plugin: serial: timeout

@danielnelson danielnelson reopened this May 15, 2020
@ssoroka
Copy link
Contributor

ssoroka commented May 15, 2020

Would this work with global coordination/sync? or does that have other problems?

@danielnelson
Copy link
Contributor

It seems that would work, however it would mean different plugin instances may interfere with each other.

@binueda
Copy link
Author

binueda commented May 16, 2020

Wow, This was a very quick response, I working with a Beagle bone with Ubuntu 20 running on it, going to use the UART of the board to connect up to 20 modbus slave for monitoring, will post on the update while i progress.
Thank you every one

@ssoroka
Copy link
Contributor

ssoroka commented May 21, 2020

@binueda let us know if you have any access/timeout problems and how severe they are.

@ray-magini
Copy link

I have the exactly same issue with using multiple modbus slaves with different slave_id(s) on one single usb device.

Aug 27 14:20:13 pi3 telegraf[2925]: 2020-08-27T12:20:13Z E! [inputs.modbus] Error in plugin: serial: timeout
Aug 27 14:20:13 pi3 telegraf[2925]: 2020-08-27T12:20:13Z E! [inputs.modbus] Error in plugin: serial: timeout
Aug 27 14:20:13 pi3 telegraf[2925]: 2020-08-27T12:20:13Z E! [inputs.modbus] Error in plugin: serial: timeout

@ssoroka You mentioned something about "global coordination/sync" which I don't quite unterstand. Is that a potential solution/workaround? If so, what do you mean by that?

Thanks!

@ssoroka
Copy link
Contributor

ssoroka commented Aug 27, 2020

You might be interested in checking out this work on a modbus gateway plugin. #8013.

@wz2b
Copy link

wz2b commented Aug 27, 2020

as @ssoroka mentioned, you can use multiple [[inputs.modbus]]

That's right, but there will be one tcp connection per remote unit, which is a problem if there are many such units attached to the gateway - it's not atypical to see gateways handle at most 4 simultaneous connections and, when you exceed that, they aren't even always smart enough to issue a connection refused.

@ray-magini
Copy link

ray-magini commented Aug 28, 2020

@ssoroka Thanks for mentioning that. As I understand it, this is for Modbus TCP, I have Modbus RTU (via serial connection - usb).

@wz2b As per my understanding this thread is not about if and how to use multiple [[inputs.modbus]] - we all do that. This threat describes the issue when you use multiple [[inputs.modbus]] and the connections (may it be Modbus TCP or Modbus RTU via USB - my case) cannot be opened in parallel (what telegraf does) and therefore it fails.

My workaround so far: I have created a systemd unit and timer which triggers every 10s and executes telegraf --config modbus_id5.conf --once; telegraf --config modbus_id6.conf --once; telegraf --config modbus_id7.conf --once;. Meaning one request runs after another

@wz2b
Copy link

wz2b commented Aug 28, 2020

This thread describes the issue when you use multiple [[inputs.modbus]] and the connections (may it be Modbus TCP or Modbus RTU via USB - my case) cannot be opened in parallel (what telegraf does) and therefore it fails.

Correct

My workaround so far: I have created a systemd unit and timer which triggers every 10s and executes telegraf --config modbus_id5.conf --once; telegraf --config modbus_id6.conf --once; telegraf --config modbus_id7.conf --once;. Meaning one request runs after another

Clever. Devices are really all over the place with how they handle this. I have some older ethernet-to-rs485 modbus gateways that I got from Automation Direct and the way they respond to too many connections is to neither accept nor reject the TCP SYN request. I have some others by Schneider Electric / PowerLogic that accept up to 4 connections, after that they accept them but the connection is just dead (never any data).

What's really helpful is you advising me you have the same problem. Your workaround will also work around the other problem: getting stuck in the infinite "mismatched transaction id" loop if the network slows down momentarily.

I should have both of those things addressed soon - they actually already are, but I asked @ssoroka to not merge until I have a chance to strengthen the README.md. Few days.

@ssoroka
Copy link
Contributor

ssoroka commented Oct 13, 2020

it might make sense for the input to have an option to force serial requests instead of parallel

@sjwang90 sjwang90 added the help wanted Request for community participation, code, contribution label Jan 28, 2021
@binueda
Copy link
Author

binueda commented Apr 29, 2021

Telegraf config file

name = "BM"
slave_id = 10
controller = "file:///dev/ttyAMA0"
baud_rate = 9600
data_bits = 8
parity = "E"
stop_bits = 1
transmission_mode = "RTU"
holding_registers = [
{ name = "Voltage", byte_order = "DCBA", data_type = "FLOAT32-IEEE", scale=0.001, address = [4101,4102]},
]

While i run a test, "telegraf -config telegraf.conf -input-filter modbus -test -debug"

[inputs.modbus] Error in plugin: modbus: exception '2' (illegal data address), function '131'

Tested the same with mbpoll below is the result

mbpoll -b 9600 -p even -m rtu -a 10 -r 4225 -c 1 -t 4:float /dev/ttyAMA0
mbpoll 1.4-25 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright © 2015-2019 Pascal JEAN, https://github.com/epsilonrt/mbpoll
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'mbpoll -w' for details.
Protocol configuration: Modbus RTU
Slave configuration...: address = [10]
start reference = 4225, count = 1
Communication.........: /dev/ttyAMA0, 9600-8E1
t/o 1.00 s, poll rate 1000 ms
Data type.............: 32-bit float (little endian), output (holding) register table
-- Polling slave 10... Ctrl-C to stop)
[4225]: 230.496
-- Polling slave 10... Ctrl-C to stop)
[4225]: 230.503

Is the serial interface of telegraf modbus module working ?

@wz2b
Copy link

wz2b commented Apr 29, 2021

Shot in the dark but: are you certain you don't have a one-off difference between zero-based and one-based register addresses? Modbus implementations are notorious for inconsistency here. The fact that you specifically got an exception 2 makes me scratch my head.

2 - The data address received in the query is not an allowable address for the slave. More specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, a request with offset 96 and length 4 would succeed, a request with offset 96 and length 5 will generate exception 02.

You are asking for [4101,4102] and I always have to deep think about do I really want [4100,4101] there instead.

@binueda
Copy link
Author

binueda commented Apr 30, 2021

Shot in the dark but: are you certain you don't have a one-off difference between zero-based and one-based register addresses? Modbus implementations are notorious for inconsistency here. The fact that you specifically got an exception 2 makes me scratch my head.

2 - The data address received in the query is not an allowable address for the slave. More specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, a request with offset 96 and length 4 would succeed, a request with offset 96 and length 5 will generate exception 02.

You are asking for [4101,4102] and I always have to deep think about do I really want [4100,4101] there instead.

Thanks for the Quick Reply, i could get this working,
how ever datasheet of the modbus slave address start with 4101

root@ubuntu:/etc/telegraf# telegraf -config telegraf.conf -input-filter modbus -test
2021-04-30T18:19:15Z I! Starting Telegraf 1.18.1
2021-04-30T18:19:15Z D! [agent] Initializing plugins
2021-04-30T18:19:15Z D! [agent] Starting service inputs

modbus,host=ubuntu,name=BM,type=holding_register Voltage=1048020294 1619806756000000000
2021-04-30T18:19:15Z D! [agent] Stopping service inputs
2021-04-30T18:19:15Z D! [agent] Input channel closed
2021-04-30T18:19:15Z D! [agent] Stopped Successfully

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/modbus feature request Requests for new plugin and for new features to existing plugins help wanted Request for community participation, code, contribution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants