Skip to content

Commit 423b6b1

Browse files
authored
Add modbus input plugin (influxdata#6154)
1 parent 41992cc commit 423b6b1

7 files changed

Lines changed: 1059 additions & 0 deletions

File tree

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ require (
4444
github.com/go-ole/go-ole v1.2.1 // indirect
4545
github.com/go-redis/redis v6.12.0+incompatible
4646
github.com/go-sql-driver/mysql v1.4.1
47+
github.com/goburrow/modbus v0.1.0
48+
github.com/goburrow/serial v0.1.0 // indirect
4749
github.com/gobwas/glob v0.2.3
4850
github.com/gofrs/uuid v2.1.0+incompatible
4951
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d
@@ -108,6 +110,7 @@ require (
108110
github.com/soniah/gosnmp v1.22.0
109111
github.com/streadway/amqp v0.0.0-20180528204448-e5adc2ada8b8
110112
github.com/stretchr/testify v1.4.0
113+
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62
111114
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00 // indirect
112115
github.com/tidwall/gjson v1.3.0
113116
github.com/vishvananda/netlink v0.0.0-20171020171820-b2de5d10e38e // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ github.com/go-redis/redis v6.12.0+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8w
150150
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
151151
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
152152
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
153+
github.com/goburrow/modbus v0.1.0 h1:DejRZY73nEM6+bt5JSP6IsFolJ9dVcqxsYbpLbeW/ro=
154+
github.com/goburrow/modbus v0.1.0/go.mod h1:Kx552D5rLIS8E7TyUwQ/UdHEqvX5T8tyiGBTlzMcZBg=
155+
github.com/goburrow/serial v0.1.0 h1:v2T1SQa/dlUqQiYIT8+Cu7YolfqAi3K96UmhwYyuSrA=
156+
github.com/goburrow/serial v0.1.0/go.mod h1:sAiqG0nRVswsm1C97xsttiYCzSLBmUZ/VSlVLZJ8haA=
153157
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
154158
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
155159
github.com/gofrs/uuid v2.1.0+incompatible h1:8oEj3gioPmmDAOLQUZdnW+h4FZu9aSE/SQIas1E9pzA=
@@ -406,6 +410,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
406410
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
407411
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
408412
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
413+
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 h1:Oj2e7Sae4XrOsk3ij21QjjEgAcVSeo9nkp0dI//cD2o=
414+
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62/go.mod h1:qUzPVlSj2UgxJkVbH0ZwuuiR46U8RBMDT5KLY78Ifpw=
409415
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00 h1:mujcChM89zOHwgZBBNr5WZ77mBXP1yR+gLThGCYZgAg=
410416
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0=
411417
github.com/tidwall/gjson v1.3.0 h1:kfpsw1W3trbg4Xm6doUtqSl9+LhLB6qJ9PkltVAQZYs=

plugins/inputs/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import (
9090
_ "github.com/influxdata/telegraf/plugins/inputs/memcached"
9191
_ "github.com/influxdata/telegraf/plugins/inputs/mesos"
9292
_ "github.com/influxdata/telegraf/plugins/inputs/minecraft"
93+
_ "github.com/influxdata/telegraf/plugins/inputs/modbus"
9394
_ "github.com/influxdata/telegraf/plugins/inputs/mongodb"
9495
_ "github.com/influxdata/telegraf/plugins/inputs/monit"
9596
_ "github.com/influxdata/telegraf/plugins/inputs/mqtt_consumer"
12 KB
Binary file not shown.

plugins/inputs/modbus/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Telegraf Input Plugin: Modbus
2+
3+
The Modbus plugin collects Discrete Inputs, Coils, Input Registers and Holding Registers via Modbus TCP or Modbus RTU/ASCII
4+
5+
### Configuration:
6+
7+
```toml
8+
## Connection Configuration
9+
##
10+
## The module supports connections to PLCs via MODBUS/TCP or
11+
## via serial line communication in binary (RTU) or readable (ASCII) encoding
12+
##
13+
## Device name
14+
name = "Device"
15+
16+
## Slave ID - addresses a MODBUS device on the bus
17+
## Range: 0 - 255 [0 = broadcast; 248 - 255 = reserved]
18+
slave_id = 1
19+
20+
## Timeout for each request
21+
timeout = "1s"
22+
23+
# TCP - connect via Modbus/TCP
24+
controller = "tcp://localhost:502"
25+
26+
# Serial (RS485; RS232)
27+
#controller = "file:///dev/ttyUSB0"
28+
#baud_rate = 9600
29+
#data_bits = 8
30+
#parity = "N"
31+
#stop_bits = 1
32+
#transmission_mode = "RTU"
33+
34+
35+
## Measurements
36+
##
37+
38+
## Digital Variables, Discrete Inputs and Coils
39+
## name - the variable name
40+
## address - variable address
41+
42+
discrete_inputs = [
43+
{ name = "Start", address = [0]},
44+
{ name = "Stop", address = [1]},
45+
{ name = "Reset", address = [2]},
46+
{ name = "EmergencyStop", address = [3]},
47+
]
48+
coils = [
49+
{ name = "Motor1-Run", address = [0]},
50+
{ name = "Motor1-Jog", address = [1]},
51+
{ name = "Motor1-Stop", address = [2]},
52+
]
53+
54+
## Analog Variables, Input Registers and Holding Registers
55+
## name - the variable name
56+
## byte_order - the ordering of bytes
57+
## |---AB, ABCD - Big Endian
58+
## |---BA, DCBA - Little Endian
59+
## |---BADC - Mid-Big Endian
60+
## |---CDAB - Mid-Little Endian
61+
## data_type - UINT16, INT16, INT32, UINT32, FLOAT32, FLOAT32-IEEE (the IEEE 754 binary representation)
62+
## scale - the final numeric variable representation
63+
## address - variable address
64+
65+
holding_registers = [
66+
{ name = "PowerFactor", byte_order = "AB", data_type = "FLOAT32", scale=0.01, address = [8]},
67+
{ name = "Voltage", byte_order = "AB", data_type = "FLOAT32", scale=0.1, address = [0]},
68+
{ name = "Energy", byte_order = "ABCD", data_type = "FLOAT32", scale=0.001, address = [5,6]},
69+
{ name = "Current", byte_order = "ABCD", data_type = "FLOAT32", scale=0.001, address = [1,2]},
70+
{ name = "Frequency", byte_order = "AB", data_type = "FLOAT32", scale=0.1, address = [7]},
71+
{ name = "Power", byte_order = "ABCD", data_type = "FLOAT32", scale=0.1, address = [3,4]},
72+
]
73+
input_registers = [
74+
{ name = "TankLevel", byte_order = "AB", data_type = "INT16", scale=1.0, address = [0]},
75+
{ name = "TankPH", byte_order = "AB", data_type = "INT16", scale=1.0, address = [1]},
76+
{ name = "Pump1-Speed", byte_order = "ABCD", data_type = "INT32", scale=1.0, address = [3,4]},
77+
]
78+
```
79+
### Example Output:
80+
81+
```
82+
$ ./telegraf -config telegraf.conf -input-filter modbus -test
83+
modbus.InputRegisters,host=orangepizero Current=0,Energy=0,Frecuency=60,Power=0,PowerFactor=0,Voltage=123.9000015258789 1554079521000000000
84+
```

0 commit comments

Comments
 (0)