InfluxDB: communication with Modbus TCP device

Hello community.
I want to set up communication between InfluxDB and Modbus TCP Server (in my case it is localost:502).

I do all instructions (telegraf.conf file configuration) according to:

but when I launch telegraf.conf file I see next message:
E! [outputs.influxdb] E! [outputs.influxdb] Failed to write metric (will be dropped: 401 Unauthorized):

What wrong I do? Is that instruciton actual?

InfluxDB runs on PC with Windows10 64bit. As Modbus Server I use software Modbus Slave (localost:502).

It is my first experience with InfluxDB. So, any information will be usefull for me.

Hello @John1,
Welcome!
Can you try:

  1. setting debug = true in the agent portion of the config and sharing the detailed telegraf logs?
  2. using the --test flag and print the metrics to stdout to make sure that the line protocol is as expected? Can you please share the line protocol?

Hello.
I start telegraf.conf using next command:

telegraf --test --config telegraf.conf

It seems to me, the modbus data has been read succesfully (especially holding regs - PowerFactor, Voltage, Energy), but they didn’t save in specified bucket.

Part of “answer” after command above executing:

swap,host=PC1 in=0i,out=0i 1654773507000000000
2022-06-09T11:18:27Z D! [inputs.modbus] trying to read coil@0[3]…
2022-06-09T11:18:27Z D! [inputs.modbus] got coil@0[3]: [0]
2022-06-09T11:18:27Z D! [inputs.modbus] field motor1_run with bit 0 @ byte 0: 0 → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field motor1_jog with bit 1 @ byte 0: 0 → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field motor1_stop with bit 2 @ byte 0: 0 → 0
2022-06-09T11:18:27Z D! [inputs.modbus] trying to read discrete@0[4]…
2022-06-09T11:18:27Z D! [inputs.modbus] got discrete@0[4]: [0]
2022-06-09T11:18:27Z D! [inputs.modbus] field start with bit 0 @ byte 0: 0 → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field stop with bit 1 @ byte 0: 0 → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field reset with bit 2 @ byte 0: 0 → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field emergency_stop with bit 3 @ byte 0: 0 → 0
2022-06-09T11:18:27Z D! [inputs.modbus] trying to read holding@0[6]…
2022-06-09T11:18:27Z D! [inputs.modbus] got holding@0[6]: [0 170 0 180 0 120 0 150 0 0 0 0]
2022-06-09T11:18:27Z D! [inputs.modbus] field PowerFactor with offset 0 with len 2: [0 170] → 170
2022-06-09T11:18:27Z D! [inputs.modbus] field Voltage with offset 2 with len 2: [0 180] → 180
2022-06-09T11:18:27Z D! [inputs.modbus] field Energy with offset 4 with len 2: [0 120] → 120
2022-06-09T11:18:27Z D! [inputs.modbus] field Current with offset 6 with len 2: [0 150] → 150
2022-06-09T11:18:27Z D! [inputs.modbus] field Frequency with offset 8 with len 2: [0 0] → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field Power with offset 10 with len 2: [0 0] → 0
2022-06-09T11:18:27Z D! [inputs.modbus] trying to read input@0[3]…
2022-06-09T11:18:27Z D! [inputs.modbus] got input@0[3]: [0 0 0 0 0 0]
2022-06-09T11:18:27Z D! [inputs.modbus] field TankLevel with offset 0 with len 2: [0 0] → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field TankPH with offset 2 with len 2: [0 0] → 0
2022-06-09T11:18:27Z D! [inputs.modbus] field Pump1-Speed with offset 4 with len 2: [0 0] → 0

Hello @John1,
You should be able to see the metrics with the test flag.
I don’t know what’s happening here. Let me loop in some telegraf experts.
Thank you for your patience.

Hi @John1,
The “401 Unauthorized” error you saw means the Telegraf output plugin isn’t configured correctly. Telegraf is trying to write the data it has gathered but isn’t allowed to connect to InfluxDB.

If you’re using InfluxDB Cloud, these instructions might help you configure the output plugin. There’s a short YouTube video that walks you through the process of configuring the output.

The instructions are a little different if you’re using InfluxDB OSS 2.x or 1.x. Those are used if you want to store your data on your local machine, not in the cloud.

Hello.
I do next steps according to video tutorial:

  1. Download “template” for telegraf.conf file from Data → Telegraf → InfluxDB Output Plugin.
  2. In this file I filled urls, token (that is connected to specified bucket), organization, bucket in
    [[outputs.influxdb_v2]] section with my data.
  3. I add [[inputs.modbus]] section where all modbus data are specified (server IP, address,
    registers information)

After executing next command:

telegraf --config telegraf2.conf

I see next response:

E! [outputs.influxdb_v2] When writing to [http://localhost:8086]: failed to write metric to ModbusPLC (401 Unauthorized): unauthorized: unauthorized access

Probably there is something I didn’t specified in telegraf2.conf file. But I don’t know what exactly.