|
| 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