Skip to content

Add Modbus Input Plugin#4623

Closed
fdamador wants to merge 9 commits into
influxdata:masterfrom
fdamador:master
Closed

Add Modbus Input Plugin#4623
fdamador wants to merge 9 commits into
influxdata:masterfrom
fdamador:master

Conversation

@fdamador
Copy link
Copy Markdown

@fdamador fdamador commented Sep 2, 2018

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

This is a new input plugin that will poll industrial controllers supporting TCP/RTU Modbus client connections. Data will be logged by register number polled.

@fdamador
Copy link
Copy Markdown
Author

fdamador commented Sep 2, 2018

The final code will need a industrial controller on the network to poll it's data. Also this specific library needs to be loaded. "github.com/goburrow/modbus"

@danielnelson
Copy link
Copy Markdown
Contributor

Thanks @fdamador, you should be able to add the modbus library by running dep ensure -add github.com/goburrow/modbus

@fdamador
Copy link
Copy Markdown
Author

fdamador commented Sep 13, 2018

Ok, a bit confused, since I'm a windows person, but deb refers to golang dep....not debian deb command.

Update - not sure what else you need me to do. Looks like gofmt here is ok with my modbus_test.go, which matches what I submitted. Also the dependencies work on my end. do you need to run dep ensure -add github.com/goburrow/modbus on your end?

@glinton
Copy link
Copy Markdown
Contributor

glinton commented Sep 14, 2018

Correct, dep is a golang command to vendor dependencies. Running dep ensure -add github.com/goburrow/modbus using dep v0.5.0 (and committing the changes) will add it to our dependency list so the ci can build properly. To run the make fmt without having make installed, run gofmt -w ./plugins/inputs/modbus/ and commit/push those changes.

Administrator added 2 commits September 14, 2018 16:22
Signed-off-by: Administrator <franklin.amador@ausenco.com>
Signed-off-by: Administrator <franklin.amador@ausenco.com>
@garciaolais
Copy link
Copy Markdown
Contributor

Hi

Yesterday I tested the plugin with my modbus controller and I have some comments

  1. conf file generated with telegraf --input-filter modbus config it is different with the documentation

conf file -> [[inputs.modbus]]
documentation - [[inputs.bond]]

https://github.com/fdamador/telegraf/blob/master/plugins/inputs/modbus/README.md#configuration

  1. The input plugin concept is collect metrics from the system, services, or 3rd party APIs

modbus plugin execute write operations

https://github.com/fdamador/telegraf/blob/0aca266fd588d4c15c36705b7000125bc3d67748/plugins/inputs/modbus/modbus.go#L152-L164

  1. modbus plugin generate a new TCP conection every time the Gather function is call it

https://github.com/fdamador/telegraf/blob/0aca266fd588d4c15c36705b7000125bc3d67748/plugins/inputs/modbus/modbus.go#L118-L120

  1. The plugin does not support read multiple register, only can read one register

https://github.com/fdamador/telegraf/blob/0aca266fd588d4c15c36705b7000125bc3d67748/plugins/inputs/modbus/modbus.go#L17-L21

@fdamador
Copy link
Copy Markdown
Author

fdamador commented Feb 20, 2019

Thank you for the comments.

  1. I don't see the difference you are referring to. Can you be more specific?

  2. Confirmed, the library uses read and write functions to the client. For the Input to Telegraf, only use the read functions.

  3. Confirmed, I'm not sure how Telegraf would keep the connection for every input plugin. If you have an plugin example then perhaps this can be achieved.

  4. Have you used a Quantity > 1?

@garciaolais
Copy link
Copy Markdown
Contributor

  1. I don't see the difference you are referring to. Can you be more specific?

If you generated the config file and open it, you can see the key [[inputs.modbus]] , but in the README the key is [[inputs.bond]]

  1. Confirmed, I'm not sure how Telegraf would keep the connection for every input plugin. If you have an plugin example then perhaps this can be achieved.

My controller only allow 10 TCP connections , when I run the plugin , 2 minutes after my controller show me 10 connections 💀

💭 I can generate a dump file with wireshark to see the tcp conections, maybe this weekend.

  1. Have you used a Quantity > 1?
    Sorry , I dont have used ...

but It is possible read different registers , I mean can I read for example , Input Contacts, Output Coils, Input Register at same time.

Signed-off-by: franklin amador <fdamador@comcast.net>
@fdamador
Copy link
Copy Markdown
Author

@garciaolais - updated plugin to handle one connection at a time. Can you retest?

@glinton - can you explain the test-go1.XXX errors I'm adding this to the master branch. Do I also need to add it to each revision?

@glinton
Copy link
Copy Markdown
Contributor

glinton commented May 20, 2019

@fdamador update your branch with our master, then remove the modbus lines from the Gopkg.toml file and run dep ensure. Push these two commits up (merge and dep ensure changing the Gopkg.lock file) and the tests should pass

Signed-off-by: franklin amador <fdamador@comcast.net>
Copy link
Copy Markdown
Contributor

@glinton glinton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also pull and merge influx's master branch into yours.

Comment thread .vscode/launch.json
Comment thread Gopkg.toml Outdated
name = "github.com/go-sql-driver/mysql"
version = "1.4.0"

[[constraint]]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to run dep ensure prior to committing the gopkg.lock changes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Not sure why when I run this on fdamador\telegraf, I get errors related to influxdata\telegraf references.

Subpackage github.com/influxdata/telegraf// is missing. (Package is required by (root).)

Comment thread plugins/inputs/modbus/modbus_test.go
@garciaolais
Copy link
Copy Markdown
Contributor

@garciaolais - updated plugin to handle one connection at a time. Can you retest?

Hi @fdamador, at this moment I dont have a modbus controller 😢 , as soon I can get one , I will test it ⚙️

btw , I made my own modbus plugin 😄 https://github.com/garciaolais/telegraf/tree/input/modbus/plugins/inputs/modbus

but I don't sended the PR because I have trouble with the testing part 😕 😖 ❓ ❓

You can check my implementation, maybe we can work and made a better version of the plugin 😃

Features

  • Handle reconection
  • Read only DiscreteInputs, Coils, Holding Registers and InputRegisters
  • You can name the register by name
  • You can scale the value
  • Byte and word ordering (endianness)
  • 16 bit register combination to 32 bit register

this is and example of a Home Energy Monitor 🏭 ⚡️ 👀 📈 using the plugin and Modbus controller
64ae4543-8a76-4137-936a-57636ecca5d4

@fdamador
Copy link
Copy Markdown
Author

fdamador commented Jun 8, 2019

@garciaolais - The best free slave simulators TCP/Serial are from PeakHMI https://www.hmisys.com/. Download section will give you everything you need.

Overall, I'm glad my initial open source code got you to code additional functionalities (bells/whistles) to get a better modbus plugin made. That's the beauty of Open Source.

Yeah, let's work together to get the testing code done. Let me know how you want to proceed.

@gregorybrzeski
Copy link
Copy Markdown
Contributor

@garciaolais, @fdamador did you join forces and is there any progress ? Do you need some help ?

@garciaolais
Copy link
Copy Markdown
Contributor

garciaolais commented Jul 14, 2019

@garciaolais, @fdamador did you join forces and is there any progress ? Do you need some help ?

@gregorybrzeski at the moment I'm not working ⛔️ 🔧 in the plugin , I hope restart working in 2 Weeks 📅

I appreciate your help!

btw. a few weeks ago 📆 I received emails 📫 from users that using the plugin

Hi Antonio
....
Enventually, I succeeded to compile and run your modbus plugin!
We are going to plug it to our PLC, and to capture something like 3500 signals per second (float, int and bool). If everything goes weel, it could easily replace our expensive industrial Historian solution!

other user

....
I write you why I want to assemble some energy meters in my house, these meters have Modbus RTU, I want to capture the data using my Raspberry.

@danielnelson danielnelson mentioned this pull request Jul 25, 2019
3 tasks
@fdamador
Copy link
Copy Markdown
Author

@garciaolais, @fdamador did you join forces and is there any progress ? Do you need some help ?

@gregorybrzeski at the moment I'm not working ⛔️ 🔧 in the plugin , I hope restart working in 2 Weeks 📅

I appreciate your help!

btw. a few weeks ago 📆 I received emails 📫 from users that using the plugin

Hi Antonio
....
Enventually, I succeeded to compile and run your modbus plugin!
We are going to plug it to our PLC, and to capture something like 3500 signals per second (float, int and bool). If everything goes weel, it could easily replace our expensive industrial Historian solution!

other user

....
I write you why I want to assemble some energy meters in my house, these meters have Modbus RTU, I want to capture the data using my Raspberry.

@fdamador fdamador closed this Jul 25, 2019
@fdamador
Copy link
Copy Markdown
Author

@garciaolais - No I have not had time to join forces yet. However, I'm glad to retract this commit since I see you are pushing your Modbus Plugin.

Very hard to make this system compile when working on a windows machine. Seems like their tools are all developed and based in Linux. I will think twice before starting another project unless I can compile it first. So many headaches!?!

@fdamador fdamador deleted the master branch July 25, 2019 23:14
@danielnelson
Copy link
Copy Markdown
Contributor

Seems like their tools are all developed and based in Linux.

Yeah for sure this is true, let me know if I can help. Once #6154 PR is building on CircleCI I will add some links to the build. Even if you don't have time for to review the code maybe you can do some testing?

@garciaolais
Copy link
Copy Markdown
Contributor

garciaolais commented Jul 26, 2019

Very hard to make this system compile when working on a windows machine. Seems like their tools are all developed and based in Linux.

@fdamador I'm using a Windows 10 machine with WSL

I can help you with your configuration

SystemInfo2

@ttjaden
Copy link
Copy Markdown

ttjaden commented Oct 25, 2019

Is there hope regarding the finishing of the plugin? I'm not a programmer but more an user and would be glad to read out Modbus TCP hardware with telegraf!

@garciaolais
Copy link
Copy Markdown
Contributor

Is there hope regarding the finishing of the plugin? I'm not a programmer but more an user and would be glad to read out Modbus TCP hardware with telegraf!

@ttjaden you can follow the plugin development in this PR 6154

I'm waiting for review 👓 .

If you need help with the actual plugin , I can help you

@ttjaden
Copy link
Copy Markdown

ttjaden commented Oct 29, 2019

@garciaolais : Is there a way to use the plugin without waiting on the official integration in telegraf? What would be the steps that I have to do without crashing my existing productive telegraf-setting?

@gregorybrzeski
Copy link
Copy Markdown
Contributor

@ttjaden there is a simple way and it works great !

Have a look at instructions which @garciaolais provided here:
#6154 (comment)

@garciaolais
Copy link
Copy Markdown
Contributor

@garciaolais : Is there a way to use the plugin without waiting on the official integration in telegraf? What would be the steps that I have to do without crashing my existing productive telegraf-setting?

@ttjaden you can use the steps shared by @gregorybrzeski but you will need to use the current development branch and if you any question we can help you

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 1, 2020

@garciaolais : Hello, where do I have to write all the commands from these instructions #6154, to make the Modbus Plugin Work through TCP?
Currently, I get this error message : dial tcp : Remote IP Address : Port : i/o timeout

Also, why do you need the WSL to make the plugin work with TCP?

Thank you.

@garciaolais
Copy link
Copy Markdown
Contributor

garciaolais commented Jun 1, 2020

Hello @D4V1D-G

Hello, where do I have to write all the commands from these instructions #6154, to make the Modbus Plugin Work through TCP?

These instructions #6154 (comment) are deprecated 😞

please check the README and note difference between my old instructions and the new readme

For example in my old comment the configuration is

 type = "TCP"
 controller="127.0.0.1"
 port = 1502

in last version is
controller = "tcp://127.0.0.1:1502"

Also, why do you need the WSL to make the plugin work with TCP?

No, you can use many options(.exe, Debian package, go run, Docker) to run the plugin.

if you have some question ❓ about how to run and config in your system, I can help you 👍

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 2, 2020

@garciaolais Thank you for your quick answer!

I am using telegraf.exe to send the data to influxdb and using exactly the same script for the controller and the rest of the plugin:
controller = "tcp://127.0.0.1:1502"

But I always get the errror:

[inputs.modbus] Error in plugin: dial tcp 10.160.81.14:7116: i/o timeout

Do you have an idea of what I am missing?
Thank you.

@garciaolais
Copy link
Copy Markdown
Contributor

garciaolais commented Jun 2, 2020

controller = "tcp://127.0.0.1:1502"

Do you have a Modbus controller in your localhost?

Can you share your config file?

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 2, 2020

The modbus controller is connected via the TCP port (10.160.81.14:7116).
Here you have my config file:

telegraf-test.zip

@garciaolais
Copy link
Copy Markdown
Contributor

I changed the ip addr in your config file and I tested with my controller

2020-06-02T14:31:44Z I! Starting Telegraf 1.14.3
> modbus,group=test,host=MX777,name=test,type=discrete_input Load=0i 1591108305000000000
> modbus,group=test,host=MX777,name=test,type=coil Enable-Load-Test-Mode=0i,Force-Load=0i,Manual-Control-Load=0i 1591108305000000000
> modbus,group=test,host=MX777,name=test,type=holding_register Battery_Capacity=0 1591108305000000000
> modbus,group=test,host=MX777,name=test,type=input_register Battery_Current=0,Battery_Power=0,Battery_SOC=0,Battery_Temp=0,Battery_Voltage=0,Consumed_Energy_Month=0,Consumed_Energy_Today=0,Consumed_Energy_Year=0,Generated_Energy_Month=0,Generated_Energy_Today=0,Generated_Energy_Year=0,Inside_Temperature=0,Load_Current=0,Load_Power=0,Load_Voltage=0,Max_Battery_Voltage=0,Max_PV_Voltage=0,Min_Battery_Voltage=0,Min_PV_Voltage=0,PV_Array_Current=0,PV_Array_Power=0,PV_Array_Voltage=0,Total_Consumed_Energy=0,Total_Generated_Energy=0 1591108305000000000

Some controller does not allow two or more simultaneous connections , please check that you can see your controller from your PC or increment the timeout setting in your config file

timeout = "1s"

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 2, 2020

@garciaolais
What controller are you using to make the connection?
Thank you.

@garciaolais
Copy link
Copy Markdown
Contributor

@D4V1D-G
I am using a modbus controller connected to my LAN, in my case 192.168.0.100:1502

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 2, 2020

@garciaolais

Some controller does not allow two or more simultaneous connections , please check that you can see your controller from your PC

image
image

After some changes with the adresses of my machines, I come up with this above. The local adress is my PC and the Distant adress is my controller. As we can see, the link is established, but I am still getting this error:
image

Have you solved a problem similar to this one?

Thank you!

@garciaolais
Copy link
Copy Markdown
Contributor

garciaolais commented Jun 2, 2020

@D4V1D-G

status message ESTABLISHED is show when you run telegraf? or when you run another thing?

What kind of modbus controller do you have?
your controller support modbus/tcp?

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 3, 2020

@garciaolais

status message ESTABLISHED is show when you run telegraf? or when you run another thing?

Indeed, it is a network data monitoring software tester, that is reading the traffic on the port.

What kind of modbus controller do you have?
your controller support modbus/tcp?

I am currently working with an EPever EPsolar Tracer3215BN and I am converting the modbus RS485 to TCP with an USR-TCP232-304.
Everything is set-up well, because I see the data on the compagnies Solar Station Monitor.

Thank you.

@garciaolais
Copy link
Copy Markdown
Contributor

@D4V1D-G

USR-TCP232-304

I can not find 🔍 any information about what modbus implementation, but I think the problem is that the converter use Modbus RTU over TCP and this protocol it is not support yet with the modbus plugin. 😞

I see another libs have problems too with that converter pymodbus-dev/pymodbus#382

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 3, 2020

@garciaolais

the converter use Modbus RTU over TCP and this protocol it is not support yet with the modbus plugin.

The converter also offers to operate with a simulated COM port so we come back to a Modbus RTU protocole.

Serial (RS485; RS232)
controller = "file:///dev/ttyUSB0"
baud_rate = 9600
data_bits = 8
parity = "N"
stop_bits = 1
transmission_mode = "RTU"

But the part in bold is a Linux configuration, if I am not mistaking. Is there a way to put the data from the simulated COM port on a windows platform on telegraf?

Thank you.

@danielnelson
Copy link
Copy Markdown
Contributor

Does #7535 help?

@D4V1D-G
Copy link
Copy Markdown

D4V1D-G commented Jun 15, 2020

@danielnelson Unfortunately, Issue #7535 does not help, because program in modbus.go is expecting a "file" or a "tcp" in the controller name, and this error message comes up in the command prompt when trying #7535 :

invalid TOML syntax

@garciaolais Here in this WSL Comment, are you using Linux because your telegraf, influxDB and grafana is on Linux?

Thanks.

@danielnelson
Copy link
Copy Markdown
Contributor

danielnelson commented Jun 15, 2020

@D4V1D-G Looks like we will need to make some code changes in order to test this. Can you open a new issue for Windows COM syntax and the modbus plugin?

-- edit -- I'll just turn 7535 into the issue to track this.

@garciaolais
Copy link
Copy Markdown
Contributor

@garciaolais Here in this WSL Comment, are you using Linux because your telegraf, influxDB and grafana is on Linux?

@D4V1D-G Actually I have telegraf+influxdb+grafana running Docker Desktop (Win 10) and I manage docker trough WSL Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants