# MODBUS connection problems

**URL:** <https://discourse.nodered.org/t/modbus-connection-problems/51786>\
**Category:** General\
**Created:** [3 October 2021 01:33 UTC](https://discourse.nodered.org/t/modbus-connection-problems/51786 "2021-10-03T01:33:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blunoz](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@blunoz](https://discourse.nodered.org/u/blunoz)\
**Post date:** [3 October 2021 01:33 UTC](https://discourse.nodered.org/t/modbus-connection-problems/51786/1 "2021-10-03T01:33:34Z")

</div>

I've got a problem connecting to a Modbus device using the Modbus Getter modules of node-red-contrib-modbus [https://github.com/BiancoRoyal/node-red-contrib-modbus](https://github.com/BiancoRoyal/node-red-contrib-modbus)

I have tested the device with a USB RS485 interface to confirm that the device works and the comms settings are correct. On the RPi I am using the serial port through a RS485 HAT by Sequent Microsystems [https://sequentmicrosystems.com/products/industrial-raspberry-pi](https://sequentmicrosystems.com/products/industrial-raspberry-pi)

Frustratingly, I actually had this working, but had to swap out the RPi and now it's not connecting.

Here's my flow:

```auto
[{"id":"99d353920c8761df","type":"modbus-getter","z":"e1a2a3efb3ac0e30","name":"","showStatusActivities":false,"showErrors":true,"logIOActivities":false,"unitid":"1","dataType":"HoldingRegister","adr":"104","quantity":"2","server":"57ec3042daf1c12f","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"keepMsgProperties":false,"x":420,"y":260,"wires":[["a0b674413829da6e"],["77f76722937b798d"]]},{"id":"5e887a415d1cd97a","type":"inject","z":"e1a2a3efb3ac0e30","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":260,"wires":[["99d353920c8761df"]]},{"id":"a0b674413829da6e","type":"debug","z":"e1a2a3efb3ac0e30","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":220,"wires":[]},{"id":"77f76722937b798d","type":"modbus-response","z":"e1a2a3efb3ac0e30","name":"","registerShowMax":20,"x":650,"y":300,"wires":[]},{"id":"57ec3042daf1c12f","type":"modbus-client","name":"","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/serial0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

```

And here is the debug output using:  
`DEBUG=contribModbus:read*,contribModbus:core:client,modbus-serial,serial node-red -v`

```auto
Welcome to Node-RED
===================

3 Oct 12:16:49 - [info] Node-RED version: v2.0.6
3 Oct 12:16:49 - [info] Node.js version: v12.22.1
3 Oct 12:16:49 - [info] Linux 5.10.17-v7+ arm LE
3 Oct 12:16:50 - [info] Loading palette nodes
3 Oct 12:16:55 - [info] Dashboard version 2.30.0 started at /ui
3 Oct 12:16:55 - [info] Settings file : /home/pi/.node-red/settings.js
3 Oct 12:16:55 - [info] HTTP Static : /home/pi/node-red-static
3 Oct 12:16:55 - [info] Context store : 'default' [module=memory]
3 Oct 12:16:55 - [info] Context store : 'persistent' [module=localfilesystem]
3 Oct 12:16:55 - [info] User directory : /home/pi/.node-red
3 Oct 12:16:55 - [info] Projects directory: /home/pi/.node-red/projects
3 Oct 12:16:55 - [info] Server now running at http://127.0.0.1:1880/admin/
3 Oct 12:16:55 - [info] Active project : LouvreController
3 Oct 12:16:55 - [info] Flows file : /home/pi/.node-red/projects/LouvreController/flows_louvrecontroller.json
3 Oct 12:16:55 - [info] +-----------------------------------------------------
3 Oct 12:16:55 - [info] | uibuilder v4.1.1 initialised
3 Oct 12:16:55 - [info] | root folder: /home/pi/.node-red/projects/LouvreController/uibuilder
3 Oct 12:16:55 - [info] | Using Node-RED's webserver at:
3 Oct 12:16:55 - [info] | http://127.0.1.1:1880/ or http://localhost:1880/
3 Oct 12:16:55 - [info] | Installed packages:
3 Oct 12:16:55 - [info] | jquery, socket.io, vue, bootstrap
3 Oct 12:16:55 - [info] | bootstrap-vue
3 Oct 12:16:55 - [info] +-----------------------------------------------------
3 Oct 12:16:56 - [info] Starting flows
  contribModbus:core:client Client -> initialized +0ms
3 Oct 12:16:56 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm init state after new
3 Oct 12:16:56 - [warn] [modbus-client:57ec3042daf1c12f] Client -> first fsm init in 500 ms Serial@/dev/serial0:9600bit/s default Unit-Id: 1
3 Oct 12:16:56 - [info] Started flows
3 Oct 12:16:56 - [info] [inject:65de767577e91594] repeat = 300000
  contribModbus:core:client Client -> RTU buffered port serial Serial@/dev/serial0:9600bit/s default Unit-Id: 1 +829ms
  contribModbus:core:client Client -> time to open Unit 1 Serial@/dev/serial0:9600bit/s default Unit-Id: 1 +120ms
  modbus-serial modbus connection opened +0ms
3 Oct 12:16:57 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm connected after state opened Get More About It By Logging Serial@/dev/serial0:9600bit/s default Unit-Id: 1
3 Oct 12:16:57 - [info] [inject:Every 2 min] repeat = 120000
3 Oct 12:16:57 - [info] [inject:Every 1 Sec] repeat = 1000
3 Oct 12:16:57 - [info] [inject:Every 30 Seconds] repeat = 120000
  modbus-serial {
  modbus-serial action: 'send serial rtu buffered',
  modbus-serial data: <Buffer 01 03 00 68 00 02 45 d7>,
  modbus-serial unitid: 1,
  modbus-serial functionCode: 3,
  modbus-serial length: 9
  modbus-serial } +0ms
  modbus-serial modbusErrorHandling:Timed out +15s
3 Oct 12:17:12 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm failed state after sending Get More About It By Logging Serial@/dev/serial0:9600bit/s default Unit-Id: 1
3 Oct 12:17:12 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm broken state after failed Get More About It By Logging Serial@/dev/serial0:9600bit/s default Unit-Id: 1
3 Oct 12:17:12 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm reconnect state after broken Get More About It By Logging Serial@/dev/serial0:9600bit/s default Unit-Id: 1
3 Oct 12:17:14 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm init state after reconnecting Serial@/dev/serial0:9600bit/s default Unit-Id: 1
3 Oct 12:17:14 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm init in 2000 ms Serial@/dev/serial0:9600bit/s default Unit-Id: 1
  contribModbus:core:client Client -> connection close sent Serial@/dev/serial0:9600bit/s default Unit-Id: 1 +19s
  contribModbus:core:client Client -> RTU buffered port serial Serial@/dev/serial0:9600bit/s default Unit-Id: 1 +2ms
  contribModbus:core:client Client -> connection closed Serial@/dev/serial0:9600bit/s default Unit-Id: 1 +6ms
  contribModbus:core:client Client -> time to open Unit 1 Serial@/dev/serial0:9600bit/s default Unit-Id: 1 +103ms
  modbus-serial modbus connection opened +4s
3 Oct 12:17:16 - [warn] [modbus-client:57ec3042daf1c12f] Client -> fsm connected after state opened Get More About It By Logging Serial@/dev/serial0:9600bit/s default Unit-Id: 1

```

I'm assuming the problem is  
` modbus-serial modbusErrorHandling:Timed out`

I have ensured that /dev/serial0 is not being used by the console by removing “console=serial0,115200” from /boot/cmdline.txt.

Is there any way to get any further level of debug info? The debug message says "Get More About It By Logging Serial@/dev/serial0:9600" but I'm not sure how to do that.

Cheers for any suggestions!  
Peter

---

<div class="post-metadata">

**Author:** ![PLCMercenary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plcmercenary/32/48855_2.png) [@PLCMercenary](https://discourse.nodered.org/u/PLCMercenary)\
**Post date:** [3 October 2021 05:58 UTC](https://discourse.nodered.org/t/modbus-connection-problems/51786/2 "2021-10-03T05:58:41Z")

</div>

So this is pretty much par for the MODBUS RTU course. I have hundreds of projects over 21 years of industrial controls. and never has one deployed where every modbus device worked without someone on site swapping a+ and b- around 4 or 5 times, at least 2 laptop reboots, Swapping usb to RS485 dongles twice, someone counting offsets on their fingers, spare 270 ohm resistors, gummy bears, chicken bones, juju, and a lot of cussing.

Can you read the device registers with another machine using CAS or ModSIM?

---

<div class="post-metadata">

**Author:** ![blunoz](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@blunoz](https://discourse.nodered.org/u/blunoz)\
**Post date:** [3 October 2021 06:36 UTC](https://discourse.nodered.org/t/modbus-connection-problems/51786/3 "2021-10-03T06:36:41Z")

</div>

Haha, thanks @PLCMercenary, glad to hear I’m not alone in my frustration with Modbus. I got this working previously with the “exact” (obviously not) same configuration so I know it’s possible.

I can read the device registers fine with a USB dongle and Windows using Qmodmaster.

What sort of chicken and juju do you recommend?

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [3 October 2021 12:05 UTC](https://discourse.nodered.org/t/modbus-connection-problems/51786/4 "2021-10-03T12:05:26Z")

</div>

Hello .. you can follow the recommendations in this [thread](https://discourse.nodered.org/t/serial-port-rs485-question/37817/2)  
that a similar RPi Hat is being used.

```plaintext
sudo raspi-config
goto '5 Interfacing Options'
goto 'P6 Serial'
'Would you like a login shell to be accessible over serial?' --> NO
'Would you like the serial port hardware to be enabled?' --> YES
Finish raspi-config
reboot the Raspberry Pi

```

> [@blunoz](#):
>
> I can read the device registers fine with a USB dongle and Windows

as a test. Can you read with the USB to RS485 dongle on the RPi ? (instead of Windows)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 December 2021 12:06 UTC](https://discourse.nodered.org/t/modbus-connection-problems/51786/5 "2021-12-02T12:06:11Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
