Unable to get Modbus plugin working

I’m using Telegraf 1.17.2 in combination with Influx 1.8.4 and Grafana v7.4.0 on a Raspberry Pi 3 (Raspberry Pi OS Full 32-bit).

If I’m only including inputs.cpu , inputs.mem , … and similar, the entire setup works fine: I can show data from the inputs on the Grafana dashboards.

However, as a next step I wanted to include a Modbus TCP/IP communication to an energy meter. I can poll the energy meter with my computer and with my home automation system, so I’m sure this communication is working.

As soon as I modify the telegraf.conf to include the section below, I can’t restart the telegraf service anymore.

Here is the modification to the telegraf.conf file:

name = "device"
slave_id = 0
timeout = "1s"
controller = "tcp://"
discrete_inputs = [{ name = "start",          address = [0]},]

When I check the status after restarting, it says the Telegraf service failed to start (code = exited, status = 1/failure).

These are only my first steps using Influx and Telegraf, so I might be overlooking something very obvious for all of you…

Thanks for your advice!

Start Telegraf manually from the command line and look at the logs, the command should look something like this:

telegraf -config telegraf.conf -test -debug

This is what the output looks like:

2021-02-09T12:35:56Z I! Starting Telegraf 1.17.2
2021-02-09T12:35:56Z I! Using config file: /etc/telegraf/telegraf.conf
2021-02-09T12:35:56Z E! [telegraf] Error running agent: Error loading config file 
/etc/telegraf/telegraf.conf: Error parsing data: line 315: invalid TOML syntax

Here is an extract from my config file, starting at line 312 :

discrete_inputs = [
     { name = "start",          address = [0]},
#     { name = "stop",           address = [1]},
#     { name = "reset",          address = [2]},
#     { name = "emergency_stop", address = [3]},

I’m running a Modbus TCP server simulator on my laptop, so I can manipulate all registers and I am sure they are available to read data from.

There is the answer, the config file (which is in TOML format) has an invalid syntax - probably in or around line 315

So I suspect a very simple error, e.g. a missing parenthesis, comma, or something like that.

Maybe leave out the last comma in the array?

I removed the three lines starting with the # and now it works…
Looks like you can’t keep commented lines inside the square brackets.

Thanks a lot for sharing your advice!

1 Like