Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
2ae7064
Add modbus path
garciaolais Mar 31, 2019
716adff
First commit
garciaolais Mar 31, 2019
531c86b
garciaolais Apr 1, 2019
ac234ee
add modbus constraint
garciaolais Apr 1, 2019
bac4a1c
add readme
garciaolais Apr 1, 2019
8d1621c
Allow for float32 registers
robinsheehy May 27, 2019
9d073d5
fix typo in example telegraf config
gregorybrzeski Jul 13, 2019
cd32ef7
fix typo in example config in code
gregorybrzeski Jul 14, 2019
e1261cc
Merge pull request #2 from gregorybrzeski/modbus-fix-typo
garciaolais Jul 14, 2019
5c175cb
Merge pull request #3 from gregorybrzeski/modbus-fix-typo
garciaolais Jul 14, 2019
0f1849d
Merge branch 'input/modbus' into patch-1
garciaolais Jul 16, 2019
ad99edd
Merge pull request #1 from robinsheehy/patch-1
garciaolais Jul 16, 2019
9268303
Fix datatype
garciaolais Jul 19, 2019
d99586e
garciaolais Jul 19, 2019
282fdb5
Remove comments
garciaolais Jul 23, 2019
cdde42e
Clean code
garciaolais Jul 23, 2019
eb6a49b
Revert "add modbus constraint"
garciaolais Apr 1, 2019
41e9a95
Merge branch 'master' into input/modbus
Jul 23, 2019
d98b45b
add modbus dependencies
Jul 23, 2019
24b253e
run dep ensure
Jul 26, 2019
6303eee
restore Gopkg.* and run dep ensure
Jul 26, 2019
1743098
update dep version, run dep ensure
Jul 26, 2019
ddbda66
run make fmt
Jul 26, 2019
a55f3fb
Use the internal.Duration type for timeout
Sep 10, 2019
608dc2a
update config, Use the internal.Duration type
Sep 10, 2019
cb72c56
change fields not settable for lowercase
Sep 10, 2019
60dc832
remove defer
Sep 10, 2019
8f6e271
remove comparing with == true, false
Sep 10, 2019
cf1315a
Remove createChunks function
Sep 12, 2019
f3fee58
fix Value , WIP
Sep 12, 2019
171d022
implement table driven test
Sep 16, 2019
acab252
change variable name
Sep 16, 2019
04f8679
revision changes
Sep 16, 2019
a501fd1
run make fmt
Sep 16, 2019
d95525b
remove constants
Sep 16, 2019
5338133
remove raw_values field
Sep 16, 2019
066a2ef
change multipe if condition for if else
Sep 16, 2019
5f9ac6a
move name variable
Sep 16, 2019
25865f3
add tag validation
Sep 16, 2019
8b16af2
run make fmt
Sep 16, 2019
3a62a54
implement ASCII Handler, add Protocol field
Sep 16, 2019
6a4a46f
run make fmt
Sep 16, 2019
d0a1a19
add comments
Sep 16, 2019
bf60d30
add sample config
Sep 16, 2019
c9b234f
Update README.md
garciaolais Sep 16, 2019
b8276a6
Update README.md
garciaolais Sep 16, 2019
d6579c4
Update modbus.go
garciaolais Sep 16, 2019
66f8c34
Update modbus.go
garciaolais Sep 16, 2019
8f01c12
Update README.md
garciaolais Sep 16, 2019
b8ba0ff
Update README.md
garciaolais Sep 16, 2019
268f1a5
Update modbus.go
garciaolais Sep 16, 2019
e8ce38c
Update modbus.go
garciaolais Sep 16, 2019
70d4471
Update README.md
garciaolais Sep 16, 2019
8e26084
Fix set Digital an Analog values
Sep 16, 2019
3e814d1
Update README.md
garciaolais Sep 16, 2019
cfeec73
run make fmt
Sep 16, 2019
4f9aa18
Refactored 'time_out' to 'timeout'
SEA-NET Sep 26, 2019
bd3d26b
Refactored 'protocol' to 'transmission_mode'
SEA-NET Sep 27, 2019
08a5e5f
Default config uses registered MODBUS/TCP port
SEA-NET Sep 27, 2019
d230b05
Config cleanup and commentary
SEA-NET Sep 27, 2019
fceaa69
Corrected typo
SEA-NET Sep 27, 2019
048553d
Merge pull request #4 from h-schwanbeck/input/modbus
garciaolais Sep 27, 2019
4280b61
Refactored struct name 'tag' to 'ModbusData'
SEA-NET Sep 29, 2019
b475c96
Struct names begin with capital letters
SEA-NET Sep 29, 2019
454064d
Struct names in CamelCase
SEA-NET Sep 29, 2019
900fe3e
Adopted golang (naming) conventions
SEA-NET Sep 29, 2019
3a70008
Fields are not tags
SEA-NET Sep 29, 2019
648ed89
Renamed 'serialHandler' to 'rtuHandler'
SEA-NET Sep 29, 2019
1d869fe
Naming conventions in test code
SEA-NET Sep 29, 2019
764e0a0
Corrected spacing
SEA-NET Sep 29, 2019
e729d55
Merge pull request #5 from h-schwanbeck/input/modbus_refactor
garciaolais Oct 4, 2019
1736ea8
run make fmt
garciaolais Oct 26, 2019
c96d5b6
changed _err , removed capitalized error string
garciaolais Nov 7, 2019
879841f
use the Init( ) error function
garciaolais Nov 7, 2019
cc4296e
change to float type
garciaolais Dec 21, 2019
e2be575
change to snake_case
garciaolais Dec 21, 2019
63104c8
add new test case
garciaolais Dec 21, 2019
cce47be
change to float type
garciaolais Dec 21, 2019
f9c3f2a
add coil name
garciaolais Dec 21, 2019
f655cc0
add validations
garciaolais Dec 21, 2019
aa76e83
remove unecessary libs
garciaolais Dec 21, 2019
13e4171
remove comment
garciaolais Dec 21, 2019
7dc4438
clean code
garciaolais Dec 21, 2019
3d67d41
remove reflection
garciaolais Dec 21, 2019
8ac6820
add method InitRegister, fix error message
garciaolais Dec 21, 2019
730d904
improve logic
garciaolais Dec 21, 2019
e1e3305
run make fmt
garciaolais Dec 21, 2019
74b24cf
update data type
garciaolais Dec 26, 2019
c6f4b3e
fix data type in config
garciaolais Dec 26, 2019
5b04015
add device name
garciaolais Dec 27, 2019
ed1928c
run make fmt
garciaolais Dec 27, 2019
cdaadce
Merge remote-tracking branch 'origin/master' into input/modbus
danielnelson Jan 29, 2020
d007490
Update go.mod/go.sum
danielnelson Jan 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ require (
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-redis/redis v6.12.0+incompatible
github.com/go-sql-driver/mysql v1.4.1
github.com/goburrow/modbus v0.1.0
github.com/goburrow/serial v0.1.0 // indirect
github.com/gobwas/glob v0.2.3
github.com/gofrs/uuid v2.1.0+incompatible
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d
Expand Down Expand Up @@ -108,6 +110,7 @@ require (
github.com/soniah/gosnmp v1.22.0
github.com/streadway/amqp v0.0.0-20180528204448-e5adc2ada8b8
github.com/stretchr/testify v1.4.0
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00 // indirect
github.com/tidwall/gjson v1.3.0
github.com/vishvananda/netlink v0.0.0-20171020171820-b2de5d10e38e // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ github.com/go-redis/redis v6.12.0+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8w
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/goburrow/modbus v0.1.0 h1:DejRZY73nEM6+bt5JSP6IsFolJ9dVcqxsYbpLbeW/ro=
github.com/goburrow/modbus v0.1.0/go.mod h1:Kx552D5rLIS8E7TyUwQ/UdHEqvX5T8tyiGBTlzMcZBg=
github.com/goburrow/serial v0.1.0 h1:v2T1SQa/dlUqQiYIT8+Cu7YolfqAi3K96UmhwYyuSrA=
github.com/goburrow/serial v0.1.0/go.mod h1:sAiqG0nRVswsm1C97xsttiYCzSLBmUZ/VSlVLZJ8haA=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gofrs/uuid v2.1.0+incompatible h1:8oEj3gioPmmDAOLQUZdnW+h4FZu9aSE/SQIas1E9pzA=
Expand Down Expand Up @@ -406,6 +410,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62 h1:Oj2e7Sae4XrOsk3ij21QjjEgAcVSeo9nkp0dI//cD2o=
github.com/tbrandon/mbserver v0.0.0-20170611213546-993e1772cc62/go.mod h1:qUzPVlSj2UgxJkVbH0ZwuuiR46U8RBMDT5KLY78Ifpw=
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00 h1:mujcChM89zOHwgZBBNr5WZ77mBXP1yR+gLThGCYZgAg=
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00/go.mod h1:eyZnKCc955uh98WQvzOm0dgAeLnf2O0Rz0LPoC5ze+0=
github.com/tidwall/gjson v1.3.0 h1:kfpsw1W3trbg4Xm6doUtqSl9+LhLB6qJ9PkltVAQZYs=
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import (
_ "github.com/influxdata/telegraf/plugins/inputs/memcached"
_ "github.com/influxdata/telegraf/plugins/inputs/mesos"
_ "github.com/influxdata/telegraf/plugins/inputs/minecraft"
_ "github.com/influxdata/telegraf/plugins/inputs/modbus"
_ "github.com/influxdata/telegraf/plugins/inputs/mongodb"
_ "github.com/influxdata/telegraf/plugins/inputs/monit"
_ "github.com/influxdata/telegraf/plugins/inputs/mqtt_consumer"
Expand Down
Binary file added plugins/inputs/modbus/.README.md.swp
Binary file not shown.
84 changes: 84 additions & 0 deletions plugins/inputs/modbus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Telegraf Input Plugin: Modbus

The Modbus plugin collects Discrete Inputs, Coils, Input Registers and Holding Registers via Modbus TCP or Modbus RTU/ASCII

### Configuration:

```toml
## Connection Configuration
##
## The module supports connections to PLCs via MODBUS/TCP or
## via serial line communication in binary (RTU) or readable (ASCII) encoding
##
## Device name
name = "Device"

## Slave ID - addresses a MODBUS device on the bus
## Range: 0 - 255 [0 = broadcast; 248 - 255 = reserved]
slave_id = 1

## Timeout for each request
timeout = "1s"

# TCP - connect via Modbus/TCP
controller = "tcp://localhost:502"

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


## Measurements
##

## Digital Variables, Discrete Inputs and Coils
## name - the variable name
## address - variable address

discrete_inputs = [
{ name = "Start", address = [0]},
{ name = "Stop", address = [1]},
{ name = "Reset", address = [2]},
{ name = "EmergencyStop", address = [3]},
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.

Can you update the sample configuration to use snake_case for the field/tag names? This will better match other Telegraf plugins.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done ✔️

]
coils = [
{ name = "Motor1-Run", address = [0]},
{ name = "Motor1-Jog", address = [1]},
{ name = "Motor1-Stop", address = [2]},
]

## Analog Variables, Input Registers and Holding Registers
## name - the variable name
## byte_order - the ordering of bytes
## |---AB, ABCD - Big Endian
## |---BA, DCBA - Little Endian
## |---BADC - Mid-Big Endian
## |---CDAB - Mid-Little Endian
## data_type - UINT16, INT16, INT32, UINT32, FLOAT32, FLOAT32-IEEE (the IEEE 754 binary representation)
## scale - the final numeric variable representation
## address - variable address

holding_registers = [
{ name = "PowerFactor", byte_order = "AB", data_type = "FLOAT32", scale=0.01, address = [8]},
{ name = "Voltage", byte_order = "AB", data_type = "FLOAT32", scale=0.1, address = [0]},
{ name = "Energy", byte_order = "ABCD", data_type = "FLOAT32", scale=0.001, address = [5,6]},
{ name = "Current", byte_order = "ABCD", data_type = "FLOAT32", scale=0.001, address = [1,2]},
{ name = "Frequency", byte_order = "AB", data_type = "FLOAT32", scale=0.1, address = [7]},
{ name = "Power", byte_order = "ABCD", data_type = "FLOAT32", scale=0.1, address = [3,4]},
]
input_registers = [
{ name = "TankLevel", byte_order = "AB", data_type = "INT16", scale=1.0, address = [0]},
{ name = "TankPH", byte_order = "AB", data_type = "INT16", scale=1.0, address = [1]},
{ name = "Pump1-Speed", byte_order = "ABCD", data_type = "INT32", scale=1.0, address = [3,4]},
]
```
### Example Output:

```
$ ./telegraf -config telegraf.conf -input-filter modbus -test
modbus.InputRegisters,host=orangepizero Current=0,Energy=0,Frecuency=60,Power=0,PowerFactor=0,Voltage=123.9000015258789 1554079521000000000
```
Loading