Telegraf Modbus RTU on Raspberry Pi - [inputs.modbus] Error in plugin: permission denied

As the header states getting “E! [inputs.modbus] Error in plugin: permission denied” log.


  interval = "10s"
  round_interval = true
  debug = true


  urls = [""]
  token = "#####"
  organization = "#####"
  bucket = "#####"


  name = "test"
  slave_id = 1
  timeout = "1s"
  debug_connection = true
  controller = "file:///dev/ttyUSB0"
  transmission_mode = "RTU"
  baud_rate = 9600
  data_bits = 8
  parity = "N"
  stop_bits = 1
  configuration_type = "register"

  input_registers = [
    {name="voltage", byte_order="ABCD", data_type="UINT32", scale=0.01, address=[1,2]},

I can read modbus register with Node-RED but getting permission denied in the log with the above .conf file.

Any assistance or guidance would be appreciated.

Hi @Duncan

I am not very well versed in Telegraf, but am using NodeRED to grab Modbus RTU data, format it, and then send to Influx. Is there any reason you are not going that route?

Hey @grant1, I have a flow in Node-RED to do this but I think parsing the data adds complexity. I’ve used Telegraf for Modbus TCP and it make’s it very simple.

Assuming there is a problem with controller = "file:///dev/ttyUSB0" but not 100% sure. Will try from a different distro to see if the problem is repeatable.

@Duncan For my own understanding (and bearing in mind I have only configured a .conf file for Telegraf once on a Raspberry Pi to grab the CPU, RAM, board temperature, etc.), where do you place your .conf file? Let’s say the Modbus RTU device is viewable through your network somewhere (e.g. connected via a USB-to-RS485 dongle connected to a PC on the LAN). How does the .conf file know where to “see” the Modbus data?

@grant1 .conf file is the default located in /etc/telegraf and Modbus RTU is a serial connection so you have to specify the usb port you are using to read the Modbus device from. In this case - file:///dev/ttyUSB0

Where you place the .conf file? On the computer running InfluxDB?

Maybe a visual is better. Like this?

Hey, that image is correct. Telegraf is installed on the Raspberry Pi (could be any hardware able to run Telegraf). Then a USB to RS485 cable is plugged from the USB port on the Raspberry Pi to the Modbus terminals on the device you want to read from. In my case an electrical meter. And yes, the file location is /etc/telegraf by default when installing Telegraf.

OK, got it. I have always used Node-RED on the Pi (or whatever is connected to the Modbus device) and had very good success using that method, but am always willing to learn new methods.

I am wondering if its a permissions issue since the telegraf service uses the telegraf user to read from the Modbus RS485. To test this theory @Duncan could you run telegraf --debug --config /foo/telegraf.conf

With root privilege

Hi @Jay_Clifford,

Additional Info:
Hardware: Raspberry Pi Zero 2 W Rev 1.0
Raspbian GNU/Linux 11 (bullseye)
Telegraf 1.25.2 (git: HEAD@67c08c51)

Have done more testing and if I run…

telegraf --debug --config telegraf.conf


telegraf --config telegraf.conf --once

This is the output…

telegraf --debug --config telegraf.conf
2023-02-20T13:49:30Z I! Starting Telegraf 1.25.2
2023-02-20T13:49:30Z I! Available plugins: 227 inputs, 9 aggregators, 26 processors, 21 parsers, 57 outputs, 2 secret-stores
2023-02-20T13:49:30Z I! Loaded inputs: modbus
2023-02-20T13:49:30Z I! Loaded aggregators:
2023-02-20T13:49:30Z I! Loaded processors:
2023-02-20T13:49:30Z I! Loaded secretstores:
2023-02-20T13:49:30Z I! Loaded outputs: influxdb_v2
2023-02-20T13:49:30Z I! Tags enabled: host=raspberrypi
2023-02-20T13:49:30Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"raspberrypi", Flush Interval:10s
2023-02-20T13:49:30Z D! [agent] Initializing plugins
2023-02-20T13:49:30Z I! [inputs.modbus] Got 1 request(s) touching 2 holding registers for 1 fields (slave 1)
2023-02-20T13:49:30Z I! [inputs.modbus] Got 0 request(s) touching 0 inputs registers for 0 fields (slave 1)
2023-02-20T13:49:30Z I! [inputs.modbus] Got 0 request(s) touching 0 discrete registers for 0 fields (slave 1)
2023-02-20T13:49:30Z I! [inputs.modbus] Got 0 request(s) touching 0 coil registers for 0 fields (slave 1)
2023-02-20T13:49:30Z D! [agent] Connecting outputs
2023-02-20T13:49:30Z D! [agent] Attempting connection to [outputs.influxdb_v2]
2023-02-20T13:49:30Z D! [agent] Successfully connected to outputs.influxdb_v2
2023-02-20T13:49:30Z D! [agent] Starting service inputs
2023-02-20T13:49:40Z D! [inputs.modbus] Reading slave 1 for file:///dev/ttyUSB0...
2023-02-20T13:49:40Z D! [inputs.modbus] trying to read holding@1[2]...
2023-02-20T13:49:40Z D! [inputs.modbus] modbus: send 01 03 00 01 00 02 95 cb
2023-02-20T13:49:40Z D! [inputs.modbus] modbus: recv 01 03 04 00 00 5e 73 83 b6
2023-02-20T13:49:40Z D! [inputs.modbus] got holding@1[2]: [0 0 94 115]
2023-02-20T13:49:40Z D! [inputs.modbus]   field voltage with offset 0 with len 4: [0 0 94 115] --> 241
2023-02-20T13:49:42Z D! [outputs.influxdb_v2] Wrote batch of 1 metrics in 1.964525271s
2023-02-20T13:49:42Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics

It works fine. I can see activity on the RS485 cable. Modbus readings on the debug output and it’s saving to InfluxDB Cloud. Once I exit those commands and run…

systemctl status telegraf

This is the output…

● telegraf.service - Telegraf
     Loaded: loaded (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-02-20 14:51:23 SAST; 55min ago
   Main PID: 3891 (telegraf)
      Tasks: 9 (limit: 407)
        CPU: 10.383s
     CGroup: /system.slice/telegraf.service
             └─3891 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

Feb 20 15:46:10 raspberrypi telegraf[3891]: 2023-02-20T13:46:10Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:13 raspberrypi telegraf[3891]: 2023-02-20T13:46:13Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:20 raspberrypi telegraf[3891]: 2023-02-20T13:46:20Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:23 raspberrypi telegraf[3891]: 2023-02-20T13:46:23Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:30 raspberrypi telegraf[3891]: 2023-02-20T13:46:30Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:33 raspberrypi telegraf[3891]: 2023-02-20T13:46:33Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:40 raspberrypi telegraf[3891]: 2023-02-20T13:46:40Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:43 raspberrypi telegraf[3891]: 2023-02-20T13:46:43Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
Feb 20 15:46:50 raspberrypi telegraf[3891]: 2023-02-20T13:46:50Z E! [inputs.modbus] Error in plugin: permission denied
Feb 20 15:46:53 raspberrypi telegraf[3891]: 2023-02-20T13:46:53Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics

So assume I’m doing something wrong or there is a bug?

@Duncan which user is used in the systemd service to start Telegraf? Is it the same as you use on the console with telegraf --config telegraf.conf --test --debug?