# Cannot Communicate with Node-Red Modbus Server (Slave)

**URL:** <https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046>\
**Category:** General\
**Tags:** modbus\
**Created:** [1 March 2024 05:35 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046 "2024-03-01T05:35:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordanv](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jordanv](https://discourse.nodered.org/u/jordanv)\
**Post date:** [1 March 2024 05:35 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/1 "2024-03-01T05:35:10Z")

</div>

I am having trouble establishing a healthy communications link with a Node-Red Modbus Slave.

_ **Context:** _  
I have created a **Node-Red Modbus Slave** on **Laptop A** , with the intent that it can be polled by a separate **Modbus Master** running on **Laptop B** (or other Modbus Master device connected on the same network).

I have created what I think should work (using the Modbus Server node) - see JSON flow code further below.

To test this I am attempting to use Modbus Poll (on Laptop B) to request the Modbus Registers from the Node-Red Modbus Slave (running on Laptop A). However, I cannot establish a healthy TCP connection.

_ **Network Troubleshooting Notes:** _

- _Laptop A_ IP Address: **192.168.1.101**
- _Laptop B_ IP Address: **192.168.1.7**
- _Laptop B_ can successfully ping _Laptop A_
- Subnet Mask and Default Gateway aligned between laptops

Node-Red Modbus Server configuration ( **Laptop A** ):

- Hostname: **192.168.1.101**
- Port: **502**

Modbus Poll configuration (Laptop B):

- Connection: **Modbus TCP/IP**
- Remote Modbus Server: **192.168.1.101**
- Server Port: **502**

Note that in the Node-Red Flow I am initialising the Modbus Holding Registers with some values so that the Modbus Master (on Laptop B) has non-zero values to retrieve. This is why the Flow contains "Modbus Flex Write" and the associated "Modbus-Client node".

Node-Red Modbus-Client configuration ( **Laptop A** ):

- Host: **192.168.1.101**
- Port: **502**

_ **Node-Red Troubleshooting Notes:** _

- I have changed the Modbus Server "Hostname" between **0.0.0.0** , **127.0.0.1** , and **192.168.1.101** (with no success)
- Node-Red version: 3.1.5
- Node.js version: v20.11.1
- Palette: node-red-contrib-modbus (5.30.0)

Any advice for troubleshooting this TCP connectivity (between Laptop B and Laptop A) would be greatly appreciated.

Some questions I have:

- The "Port" field for the Modbus Server Node suggests the available range is "2000 to 65536" (this is the grey text within the field when nothing is yet entered into the field). The default setting is 10502, but I have this set to 502, which is outside the "grey-text" range - is this an issue?
- Are there specific Firewall rules that need to be enabled/disabled to allow Node-Red to communicate through?

---

<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:** [1 March 2024 05:42 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/2 "2024-03-01T05:42:38Z")

</div>

If your OS is Linux (maybe macOS too - idk) there are permissions required to bind ports below 1000.

On windows, you'll likely need to open port 502 in the built in firewall.

Did you try accessing the server by adding a client on the same node-red?

---

<div class="post-metadata">

**Author:** ![jordanv](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jordanv](https://discourse.nodered.org/u/jordanv)\
**Post date:** [1 March 2024 05:46 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/3 "2024-03-01T05:46:16Z")

</div>

Hi Steve,

Thanks for the prompt response.

- I am running Windows
- I have a Modbus Client on the same Node-Red and it can read and write from the Modbus Server correctly (within the same Flow).

Note I have tried to upload my JSON code here, but it is too many characters (\>32000) - even though the flow is not actually that large/complex.

---

<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:** [1 March 2024 05:46 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/4 "2024-03-01T05:46:31Z")

</div>

Forgot to ask. Is there a specific reason for using modbus? (There are much better ways to do intercommunication between Node-RED instances)

---

<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:** [1 March 2024 05:47 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/5 "2024-03-01T05:47:19Z")

</div>

> [@jordanv](#):
>
> I have a Modbus Client on the same Node-Red and it can read and write from the Modbus Server correctly (within the same Flow)

That suggests firewall to me.

---

<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:** [1 March 2024 05:48 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/6 "2024-03-01T05:48:30Z")

</div>

> [@jordanv](#):
>
> Note I have tried to upload my JSON code here, but it is too many characters (\>32000) - even though the flow is not actually that large/complex.

You can select only the nodes of interest before export to minimise the export size

---

<div class="post-metadata">

**Author:** ![jordanv](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jordanv](https://discourse.nodered.org/u/jordanv)\
**Post date:** [1 March 2024 05:48 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/7 "2024-03-01T05:48:55Z")

</div>

Yes, ultimately I need a Modbus Master device (a 3rd-party device) to retrieve Modbus from Node-Red (I am using Laptop B purely to troubleshoot before connecting the 3rd-party device).

I am using Node-Red to simulate a Modbus Slave (solar inverters), to allow easier testing on the bench.

---

<div class="post-metadata">

**Author:** ![jordanv](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jordanv](https://discourse.nodered.org/u/jordanv)\
**Post date:** [1 March 2024 05:53 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/8 "2024-03-01T05:53:37Z")

</div>

Modbus Server JSON:

```auto
[
    {
        "id": "49bae4e7.6cc76c",
        "type": "modbus-server",
        "z": "3993d0ae18e25663",
        "name": "Modbus Server",
        "logEnabled": true,
        "hostname": "192.168.1.101",
        "serverPort": "502",
        "responseDelay": 100,
        "delayUnit": "ms",
        "coilsBufferSize": "9999",
        "holdingBufferSize": "49999",
        "inputBufferSize": "9999",
        "discreteBufferSize": "9999",
        "showErrors": true,
        "x": 678.9999713897705,
        "y": 188.99999380111694,
        "wires": [
            [
                "27095842.c16878"
            ],
            [
                "27095842.c16878"
            ],
            [
                "27095842.c16878"
            ],
            [],
            []
        ]
    }
]

```

Modbus-Client JSON:

```auto
[
    {
        "id": "ca982324.01be8",
        "type": "modbus-flex-write",
        "z": "3993d0ae18e25663",
        "name": "",
        "showStatusActivities": false,
        "showErrors": true,
        "showWarnings": true,
        "server": "48496f3b.10762",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 1210,
        "y": 380,
        "wires": [
            [],
            [
                "ef1ff17b.cd3fe"
            ]
        ]
    },
    {
        "id": "48496f3b.10762",
        "type": "modbus-client",
        "name": "local",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": false,
        "tcpHost": "192.168.1.101",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "",
        "unit_id": 1,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectOnTimeout": false,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": false,
        "showErrors": false,
        "showWarnings": true,
        "showLogs": true
    }
]

```

---

<div class="post-metadata">

**Author:** ![jordanv](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jordanv](https://discourse.nodered.org/u/jordanv)\
**Post date:** [1 March 2024 05:58 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/9 "2024-03-01T05:58:27Z")

</div>

To test the general Firewalls between laptops I have run up the Modbus Slave App (from Modbustools) on Laptop A.

With Laptop B (running Modbus Poll) I was then able to correctly read Modbus registers from Laptop A.

Given that Laptop B can't establish a healthy connection with the Laptop A Node-Red Modbus Slave, does this suggest that there are Firewall rules specific to Node-Red that I need to enable/establish?

---

<div class="post-metadata">

**Author:** ![jordanv](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jordanv](https://discourse.nodered.org/u/jordanv)\
**Post date:** [1 March 2024 06:17 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/10 "2024-03-01T06:17:05Z")

</div>

Thanks for the prompt Steve, the solution was indeed a Firewall rule (on Laptop A running Node-Red).

I created a new Firewall rule specifically allowing Inbound TCP Port 502.

I'm slightly confused given that other TCP Port connections (such as 503) were working despite not having a dedicated Firewall rule allowing them.

But this has it working, and I'm grateful. Thankyou.

---

<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 2024 06:18 UTC](https://discourse.nodered.org/t/cannot-communicate-with-node-red-modbus-server-slave/86046/11 "2024-03-15T06:18:04Z")

</div>

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