# Can't connect to Modbus TCP server (that is running 100%)

**URL:** <https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916>\
**Category:** General\
**Tags:** modbus\
**Created:** [24 February 2022 10:35 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916 "2022-02-24T10:35:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [24 February 2022 10:35 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/1 "2022-02-24T10:35:11Z")

</div>

I have a running Modbus TCP server on a PLC with these parameters:

- IP: 192.168.1.10
- Port: 502
- Device address: 1
- Holding register on address 1 with heartbeat variable

I know for sure that the Modbus TCP server is running because I have tried connecting to it via Python script sucesfully:

```auto
from pyModbusTCP.client import ModbusClient

host = '192.168.1.10'
port = 502

client = ModbusClient(host, port, unit_id = 1)
client.open()
hr = client.read_holding_registers(0,10)

print(hr)

Output:
[310, 0, 0, 0, 0, 0, 0, 0, 0, 0]

```

My Node-red gets stuck in registered state always:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70d2e49b8b9141a9cdf29b074e249700f99b16c6.png)

When I force it to connect it sends out this messeges:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/de338917d33dca800b8e7a8722db665802d0f0aa.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5abdb9a1ae87d961f1d3e806db971a73eb89d349.png)

Any suggestions guys? I don't know what to try at this point.

This is my flow I am using on my Node-Red:  
`[{"id":"683bce4b.da7ed","type":"modbus-read","z":"f0f61dbf.5d964","name":"Modbus TCP","topic":"","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"unitid":"1","dataType":"HoldingRegister","adr":"0","quantity":"2","rate":"1","rateUnit":"s","delayOnStart":true,"startDelayTime":"1","server":"610770cd.6c00c","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":true,"x":330,"y":700,"wires":[["6361d552.0f5f2c"],["1fed322a.4e6bce"]]},{"id":"6361d552.0f5f2c","type":"debug","z":"f0f61dbf.5d964","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":680,"wires":[]},{"id":"1fed322a.4e6bce","type":"debug","z":"f0f61dbf.5d964","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":720,"wires":[]},{"id":"610770cd.6c00c","type":"modbus-client","name":"mark220LX - TCP","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":true,"queueLogEnabled":true,"tcpHost":"192.168.1.10","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]`

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 February 2022 15:48 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/2 "2022-02-24T15:48:22Z")

</div>

> [@Sulomus](#):
>
> Any suggestions guys?

Have you checked the [issues on the github repository](https://github.com/BiancoRoyal/node-red-contrib-modbus/issues?q=is%3Aissue+is%3Aopen+not+ready) for similar issues?

Is the node-red server on the same network (e.g. can the machine running node-red ping the PLC)?

Have you tried [other modbus nodes](https://flows.nodered.org/search?term=modbus&type=node)?

---

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [24 February 2022 16:31 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/3 "2022-02-24T16:31:58Z")

</div>

I can't go to the first link you posted unfortunately :c

Yes I have tried other Nodes - all fail. I have even tried to import modbus-stream third party library and it also fails (to my surprise with no error messages!) ...

---

<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:** [24 February 2022 18:58 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/4 "2022-02-24T18:58:08Z")

</div>

Have you also tried with Modbus Flex Getter instead of Modbus Read node ?

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

```auto
[{"id":"1fed322a.4e6bce","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":810,"y":1640,"wires":[]},{"id":"c564e90ec1c46867","type":"modbus-flex-getter","z":"54efb553244c241f","name":"","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"server":"610770cd.6c00c","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":600,"y":1660,"wires":[["1fed322a.4e6bce"],[]]},{"id":"cfda606228934e05","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":1660,"wires":[["63ba7d9945104484"]]},{"id":"63ba7d9945104484","type":"function","z":"54efb553244c241f","name":"","func":"msg.payload = {\n value: msg.payload,\n 'fc': 3,\n 'unitid': 1,\n 'address': 0,\n 'quantity': 2\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":1660,"wires":[["c564e90ec1c46867"]]},{"id":"610770cd.6c00c","type":"modbus-client","name":"mark220LX - TCP","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.10","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"30","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]

```

---

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [24 February 2022 21:19 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/5 "2022-02-24T21:19:12Z")

</div>

I will try it tomorrow right away!

I have done some further testing and have strange results:

- when I run NodeRed on my Windows 11 notebook I can connect with the same flow without any problem to the PLC.
- but when I run the code on my Raspberry PI I can't. I have even checked the versions and they are the same.

I will try tomorrow your suggestions + logging to see what's really going under the hood.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 February 2022 21:42 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/6 "2022-02-24T21:42:44Z")

</div>

> [@Steve-Mcl](#):
>
> can the machine running node-red ping the PLC)

@Sulomus Did you answer that question?

---

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [25 February 2022 09:31 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/7 "2022-02-25T09:31:32Z")

</div>

The devices can see each other and are on the same network:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/30e95b05893b82e87d4989ce0ccda74c7725b7c4.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 February 2022 09:33 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/8 "2022-02-25T09:33:03Z")

</div>

> [@Sulomus](#):
>
> The devices can see each other and are on the same network

> [@Sulomus](#):
>
> - when I run NodeRed on my Windows 11 notebook I can connect with the same flow without any problem to the PLC.
> - but when I run the code on my Raspberry PI I can't. I have even checked the versions and they are the same

So that suggests a problem with the PI.

What versions of NODE and Node-RED run on both these devices?

---

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [25 February 2022 09:33 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/9 "2022-02-25T09:33:10Z")

</div>

> [@UnborN](#):
>
> Have you also tried with Modbus Flex Getter instead of Modbus Read node ?

Using `Modbus Flex Getter` from your code results in same error:

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

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

---

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [25 February 2022 09:35 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/10 "2022-02-25T09:35:08Z")

</div>

> [@Steve-Mcl](#):
>
> So that suggests a problem with the PI.
> 
> What versions of NODE and Node-RED run on both these devices?

The device that is trying to connect to the Modbus Server:

```auto
25 Feb 09:33:44 - [info] Node-RED version: v2.1.4
25 Feb 09:33:44 - [info] Node.js version: v12.22.8

```

The device serving the Modbus Server is a PLC that is not running NodeRed (so I can't provide any info regarding NODE and NodeRed version).

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 February 2022 09:38 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/11 "2022-02-25T09:38:37Z")

</div>

No, when i said "So that suggests a problem with the PI." I meant compared to the Windows 11 PC that does connect

> [@Sulomus](#):
>
> - when I run NodeRed on my Windows 11 notebook I can connect with the same flow without any problem to the PLC.
> - but when I run the code on my Raspberry PI I can't. I have even checked the versions and they are the same.

So again, What versions of NODE and Node-RED run on both these devices (the PI and the Win 11 machine)

---

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [25 February 2022 09:43 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/12 "2022-02-25T09:43:42Z")

</div>

Windows 11:

```auto
25 Feb 10:41:59 - [info] Node-RED version: v2.2.0
25 Feb 10:41:59 - [info] Node.js version: v16.14.0

```

Raspberry PI:

```auto
25 Feb 09:33:44 - [info] Node-RED version: v2.1.4
25 Feb 09:33:44 - [info] Node.js version: v12.22.8

```

I know what you're suggesting - get the same versions of SW. I have tried that with [bash script for updating on Raspberry PI](https://nodered.org/docs/getting-started/raspberrypi).

When I updated the NodeRed the same result occurred 😕

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 February 2022 10:05 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/13 "2022-02-25T10:05:11Z")

</div>

> [@Sulomus](#):
>
> When I updated the NodeRed the same result occurred

Did you upgrade node red and nodejs? Why did you go back to the old version again?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 February 2022 10:05 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/14 "2022-02-25T10:05:27Z")

</div>

All I can say it is that you have it working on one computer but not on the PI

It stands to reason there is an issue with the pi (leaving aside the architecture and OS differences)

I know there are plenty running modbus on PI so that leaves me one conclusion - that there is an issue with the PI (be that FW/network or borked node/nodejs)

Do you have a spare SD card to build a new clean image?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 February 2022 11:41 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/15 "2022-02-25T11:41:34Z")

</div>

Have you made changes to the firewall settings on the pi? Perhaps you have blocked the port.

---

<div class="post-metadata">

**Author:** ![Sulomus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sulomus/32/49578_2.png) [@Sulomus](https://discourse.nodered.org/u/Sulomus)\
**Post date:** [25 February 2022 11:49 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/16 "2022-02-25T11:49:23Z")

</div>

> [@Steve-Mcl](#):
>
> Have you checked the [issues on the github repository](https://github.com/BiancoRoyal/node-red-contrib-modbus/issues?q=is%3Aissue+is%3Aopen+not+ready) for similar issues?

I have checked now (today the link is working, yesterday it wasn't idk what changed)

I have found [this issue](https://github.com/BiancoRoyal/node-red-contrib-modbus/issues/244) describing that this can occur because `"it needs some time in the physical world to connect"`:

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

So I have set a delay on start:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/4/44830d6329492428e1a4b105828d71549dfea537.png)

Now everything is working ... !!! Such a simple think that didn't occur to me for the whole day.  
**Thank you ALL for the help and sorry for wasting your time ...**

I am still curiouse why this doesn't need to be setup on my Win11 machine but it has to be on Raspberry PI ... 🤔

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 February 2022 13:32 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/17 "2022-02-25T13:32:52Z")

</div>

> [@Sulomus](#):
>
> sorry for wasting your time

Not wasted at all, we have learnt from this and may remember to make the suggestion when another has the same problem.

---

<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:** [11 March 2022 13:33 UTC](https://discourse.nodered.org/t/cant-connect-to-modbus-tcp-server-that-is-running-100/58916/18 "2022-03-11T13:33:03Z")

</div>

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