# Modbus RTU problem

**URL:** <https://discourse.nodered.org/t/modbus-rtu-problem/56450>\
**Category:** Industrial\
**Created:** [11 January 2022 08:54 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450 "2022-01-11T08:54:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmm](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jmm](https://discourse.nodered.org/u/jmm)\
**Post date:** [11 January 2022 08:54 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/1 "2022-01-11T08:54:00Z")

</div>

Hi everyone!

I am using a raspberry pi 3 to read data from a sensor. The communication protocol is modbus rtu. To connect the sensor I am using the adapter of the picture. The nodes I use are "node-red-contrib-modbus 5.16.0".

Everything works perfectly until the raspi reboot. When I reboot the raspi the nodes are unable to reconnect with the sensor. The same problem occurs if I deploy NodeRed again. If I want to reconnect it I have to unplug the usb, go to the server configuration, check that the usb is not in the list, then connect it again and select the correct usb. Has anything similar ever happened to you?

I have try to solve the problem enabling the delay option and setting it with 60s but this does not work... Any help will be appreciated!

 ![Adaptador modbus](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/1189c45b13b3972dc5dfd181eabfe4444442d2d9.jpeg)

---

<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:** [11 January 2022 13:32 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/2 "2022-01-11T13:32:21Z")

</div>

> [@jmm](#):
>
> If I want to reconnect it I have to unplug the usb, go to the server configuration, check that the usb is not in the list, then connect it again and select the correct usb. Has anything similar ever happened to you?

Hello .. i use a usb to serial converter also and never had a problem .. im using a RPi4.

The modbus node config is set to  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e0727f28977b2c6377d0de2bbee5061cf960ba1.png)

in my setup the device always has the same number (ttyUSB0) since its the only usb device connected.  
What about in your setup ? As i see in the screenshot you dont have anything else except the mini hdmi and power usb.

What does `ls /dev/ttyUSB*` give when the device is running ok and what when you get a disconnect ?

Silly question but have you tried a different usb port also ?

Do you get any modbus related errors in the node-red terminal when the nodes cannot reconnect ?

---

<div class="post-metadata">

**Author:** ![jmm](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jmm](https://discourse.nodered.org/u/jmm)\
**Post date:** [12 January 2022 09:33 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/3 "2022-01-12T09:33:30Z")

</div>

> [@UnborN](#):
>
> What does `ls /dev/ttyUSB*` give when the device is running ok and what when you get a disconnect ?

When is running ok: /dev/ttyUSB0 When got disconnected from node-red: /dev/ttyUSB0 When I disconnected the converter from the raspi: No such file or directory

> [@UnborN](#):
>
> have you tried a different usb port also ?

Yes, I tried all the ports and two converters.

> [@UnborN](#):
>
> Do you get any modbus related errors in the node-red terminal when the nodes cannot reconnect ?

I don't know if this is an error but when I try to active the flow with the modbus node, it got disconnected a moment and then it connect again but showing connected instead of active:

![Captura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e8d1ca28c38acbabb034f894c993f447357be5fa.png)

---

<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:** [12 January 2022 10:42 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/4 "2022-01-12T10:42:08Z")

</div>

> [@jmm](#):
>
> When got disconnected from node-red: /dev/ttyUSB0

So the device is still there and the RPi can still see it.  
that means the modbus node cannot communicate with it.

What version of Nodejs you have installed ?  
`node -v`

by the way i just noticed that you said 60 seconds for delay ?? you mean Modbus delay 60s ?  
thats to long .. here is my config

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c0d412f605e3e33d83296300d4dbd638f8e6946.png)

Confirm your device's Baud rate settings

Can you share your flow to see the rest of your setup ?

---

<div class="post-metadata">

**Author:** ![jmm](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jmm](https://discourse.nodered.org/u/jmm)\
**Post date:** [14 January 2022 09:28 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/5 "2022-01-14T09:28:04Z")

</div>

> [@UnborN](#):
>
> What version of Nodejs you have installed ?

v2.1.4

> [@UnborN](#):
>
> Confirm your device's Baud rate settings

This is ok, since I can communicate sometimes.

The flow is:

```auto
[{"id":"705b8111668bdc06","type":"debug","z":"52cd3d86b0ad24b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":240,"wires":[]},{"id":"71c73b087a382df5","type":"debug","z":"52cd3d86b0ad24b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":280,"wires":[]},{"id":"34f08b45633bbf38","type":"modbus-read","z":"52cd3d86b0ad24b8","name":"Interfacial temperature pre reference","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"202","quantity":"2","rate":"30","rateUnit":"s","delayOnStart":true,"startDelayTime":"60","server":"6201b97892a33d68","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":200,"y":260,"wires":[["705b8111668bdc06"],["71c73b087a382df5"]]},{"id":"6201b97892a33d68","type":"modbus-client","name":"","clienttype":"simpleser","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"115200","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"2","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"200","parallelUnitIdsAllowed":true}]

```

---

<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:** [14 January 2022 12:09 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/6 "2022-01-14T12:09:48Z")

</div>

> [@jmm](#):
>
> v2.1.4

Thats the Node-red version .. whats the Node js version ? From terminal run `node -v`  
The Modbus nodes officially support Nodejs version up to version 14. ([Github link](https://github.com/BiancoRoyal/node-red-contrib-modbus))

Enable these option in Modbus node to get a more detailed status notification  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2b7bcf73c3906ae3918ddec62aa8407fc5f99783.png)

Do you also get the same errors if you use the **Modbus-Flex-Getter** node instead ?

Have you tried lowering the 115200 baud rate to something lower on both the device and the node ?

Also increase the Reconnect to 2000 ms instead of 200 to avoid throttling the device after a disconnection.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/16562560f64c9c26d621683eef0ace534c554553.png)

---

<div class="post-metadata">

**Author:** ![jmm](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jmm](https://discourse.nodered.org/u/jmm)\
**Post date:** [14 January 2022 13:13 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/7 "2022-01-14T13:13:46Z")

</div>

> [@UnborN](#):
>
> whats the Node js version ?

Sorry, the versión is v12.22.5

> [@UnborN](#):
>
> Do you also get the same errors if you use the **Modbus-Flex-Getter** node instead ?

I didn't try it, but I will!

> [@UnborN](#):
>
> Have you tried lowering the 115200 baud rate to something lower on both the device and the node ?

The manual of the device doesn't show how to make it so I can't try this

---

<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:** [15 March 2022 13:14 UTC](https://discourse.nodered.org/t/modbus-rtu-problem/56450/8 "2022-03-15T13:14:00Z")

</div>

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