# Raspberry Pi Modbus TCP, port 502 not listening

**URL:** <https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625>\
**Category:** General\
**Created:** [7 November 2018 01:19 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625 "2018-11-07T01:19:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfsoo01](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@kfsoo01](https://discourse.nodered.org/u/kfsoo01)\
**Post date:** [7 November 2018 01:19 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/1 "2018-11-07T01:19:00Z")

</div>

Hi,  
I installed node-red in my Raspberry Pi, and would like to apply with Modbus TCP; however, it is not listening on port 502. Please help..

pi@raspberrypi:~ $ netstat --tcp --listening  
Active Internet connections (only servers)  
Proto Recv-Q Send-Q Local Address Foreign Address State  
tcp 0 0 0.0.0.0:5900 0.0.0.0:\* LISTEN  
tcp 0 0 0.0.0.0:ssh 0.0.0.0:\* LISTEN  
tcp 0 0 localhost:ipp 0.0.0.0:\* LISTEN  
tcp 0 0 0.0.0.0:1880 0.0.0.0:\* LISTEN  
tcp 0 0 localhost:postgresql 0.0.0.0:\* LISTEN  
tcp6 0 0 [::]:9001 [::]:\* LISTEN  
tcp6 0 0 [::]:5900 [::]:\* LISTEN  
tcp6 0 0 [::]:http-alt [::]:\* LISTEN  
tcp6 0 0 [::]:http [::]:\* LISTEN  
tcp6 0 0 [::]:ssh [::]:\* LISTEN  
tcp6 0 0 localhost:ipp [::]:\* LISTEN  
tcp6 0 0 localhost:postgresql [::]:\* LISTEN  
tcp6 0 0 [::]:1883 [::]:\* LISTEN  
tcp6 0 0 [::]:https [::]:\* LISTEN

```auto
[{"id":"5b001706.0c6338","type":"modbus-read","z":"ad821627.ea6c98","name":"mb","topic":"t1","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"unitid":"","dataType":"InputRegister","adr":"0","quantity":"1","rate":"1","rateUnit":"m","delayOnStart":false,"startDelayTime":"","server":"fcf4c99f.568bd8","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":210,"y":140,"wires":[["68a762c.498449c"],[]]},{"id":"fcf4c99f.568bd8","type":"modbus-client","z":"","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":true,"tcpHost":"192.168.0.12","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"60000","clientTimeout":"1000","reconnectTimeout":"2000"}]

```

node-red  
6 Nov 19:07:01 - [info]

# Welcome to Node-RED

6 Nov 19:07:01 - [info] Node-RED version: v0.19.5  
6 Nov 19:07:01 - [info] Node.js version: v8.11.1  
6 Nov 19:07:01 - [info] Linux 4.14.71-v7+ arm LE  
6 Nov 19:07:03 - [info] Loading palette nodes  
6 Nov 19:07:07 - [warn] [modbustcp-no-pooling-server] Deprecated call to RED.runtime.nodes.registerType - node-set name must be provided as first argument  
6 Nov 19:07:07 - [warn] [modbustcp-no-pooling-write] Deprecated call to RED.runtime.nodes.registerType - node-set name must be provided as first argument  
6 Nov 19:07:07 - [warn] [modbustcp-no-pooling-read] Deprecated call to RED.runtime.nodes.registerType - node-set name must be provided as first argument  
6 Nov 19:07:08 - [info] Dashboard version 2.10.1 started at /ui  
6 Nov 19:07:09 - [info] Settings file : /home/pi/.node-red/settings.js  
6 Nov 19:07:09 - [info] Context store : 'default' [module=memory]  
6 Nov 19:07:09 - [info] User directory : /home/pi/.node-red  
6 Nov 19:07:09 - [warn] Projects disabled : editorTheme.projects.enabled=false  
6 Nov 19:07:09 - [info] Flows file : /home/pi/.node-red/flows\_frisco-pi-2.json  
6 Nov 19:07:09 - [info] Server now running at [http://127.0.0.1:1880/](http://127.0.0.1:1880/)  
6 Nov 19:07:09 - [warn]

* * *

Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials  
file will not be recoverable, you will have to delete it and re-enter  
your credentials.

## You should set your own key using the 'credentialSecret' option in your settings file. Node-RED will then re-encrypt your credentials file using your chosen key the next time you deploy a change.

6 Nov 19:07:09 - [info] Starting flows  
6 Nov 19:07:09 - [info] Started flows

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [7 November 2018 04:55 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/2 "2018-11-07T04:55:07Z")

</div>

> [@kfsoo01](#):
>
> I installed node-red in my Raspberry Pi, and would like to apply with Modbus TCP; however, it is not listening on port 502.

The node-red Modbus client nodes are used to **connect to and read data from** a previously installed and running OPC server -- which does not appear to be running on your raspberry pi (which is not surprising). So where is the server actually running?

---

<div class="post-metadata">

**Author:** ![kfsoo01](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@kfsoo01](https://discourse.nodered.org/u/kfsoo01)\
**Post date:** [7 November 2018 13:54 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/3 "2018-11-07T13:54:35Z")

</div>

Thanks Steve, I am looking to have node-red to connect with 502 and read data from an external Modbus client which is sitting on the same vlan. How can I make it work like the youtube describe below? Do I have to install an OPC on my raspberry pi?

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [7 November 2018 14:56 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/4 "2018-11-07T14:56:07Z")

</div>

Ah, ok, I thought you were looking on the local pi for the modbus server...

> [@kfsoo01](#):
>
> pi@raspberrypi:~ $ netstat --tcp --listening  
> Active Internet connections (only servers)

I noticed that last line says it's showing **only servers** -- but yes, if the server is on your lan, you should be able to connect to the remote port 502, giving the hostname or ip addr of the remote server.

Does the modbus-read node ever get connected to the server? What makes you think that it's not listening? A picture of your flow may be helpful here, since most of us are not going to be able to import a flow that contains modbus and serial nodes.

FYI, please edit your original post and put a separate line containing 3 backtics (`````) before and after your flow json. This keeps the discourse forum from formatting the text for display, and potentially messing up quotes and other characters, which makes the flow not able to be imported.

---

<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:** [7 November 2018 15:35 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/5 "2018-11-07T15:35:18Z")

</div>

> [@kfsoo01](#):
>
> I am looking to have node-red to connect with 502 and read data from an external Modbus client

I believe that with modbus TCP you have to have a server. If the external device is a client (not a server) then you have to run a server for it to connect to. Then the node-red node can also connect to that server. If, however, the external device can operate as a server then do that and the node red node should be able to connect to it.

---

<div class="post-metadata">

**Author:** ![kfsoo01](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@kfsoo01](https://discourse.nodered.org/u/kfsoo01)\
**Post date:** [7 November 2018 16:59 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/6 "2018-11-07T16:59:28Z")

</div>

I run a capture using tcpdump, look like node-red (IP: 192.168.0.13) is sending a random port instead of port 502. Is there anyway to bind it for port 502?

10:50:24.048609 IP 192.168.0.13.53660 \> 192.168.0.12.502: Flags [S], seq 793996539, win 29200, options [mss 1460,sackOK,TS val 3542014307 ecr 0,nop,wscale 7], length 0  
10:50:24.258612 IP 192.168.0.12.502 \> 192.168.0.13.53660: Flags [R.], seq 0, ack 793996540, win 0, length 0

---

<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:** [7 November 2018 17:22 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/7 "2018-11-07T17:22:58Z")

</div>

I believe you are misinterpreting that. I believe it is saying that 0.13 has sent to 0.12 port 502, then 0.12 replies to 0.13 port 53660

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [7 November 2018 21:09 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/8 "2018-11-07T21:09:07Z")

</div>

I concur with Colin... it looks like thngs are working ok. But you didn't answer my other questions:

> [@shrickus](#):
>
> Does the modbus-read node ever get connected to the server? What makes you think that it's not listening?

Do you have any nodes wired to the input of the `modbus` node? Is it configured to poll the server?

---

<div class="post-metadata">

**Author:** ![kfsoo01](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@kfsoo01](https://discourse.nodered.org/u/kfsoo01)\
**Post date:** [7 November 2018 21:20 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/9 "2018-11-07T21:20:14Z")

</div>

What I tried to do was to have Node-Red query/Read Modbus Master/Server over TCP.

I have the config below at node-red

```auto
"tcpHost":"192.168.0.12","tcpPort":"502","tcpType":"DEFAULT"

```

Both of them are on the same network.  
192.168.0.13 (Node-red) --\> 192.168.0.12 (Modbus Server)

---

<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:** [7 November 2018 22:02 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/10 "2018-11-07T22:02:04Z")

</div>

You didn't answer the question about what you have wired to the input.  
Also what is it that is not working.

---

<div class="post-metadata">

**Author:** ![kfsoo01](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@kfsoo01](https://discourse.nodered.org/u/kfsoo01)\
**Post date:** [7 November 2018 22:10 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/11 "2018-11-07T22:10:10Z")

</div>

the input should be sent from Modbus Server via TCP, right? the node-red I want to use is just capture from Modbus Server/PLC.

---

<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:** [8 November 2018 09:04 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/12 "2018-11-08T09:04:26Z")

</div>

You still haven't told us what isn't working.

---

<div class="post-metadata">

**Author:** ![kfsoo01](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@kfsoo01](https://discourse.nodered.org/u/kfsoo01)\
**Post date:** [8 November 2018 16:54 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/13 "2018-11-08T16:54:14Z")

</div>

My node-red fails to connect to Modbus server via TCP. It keep re-initiates the connection.

---

<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:** [8 November 2018 17:54 UTC](https://discourse.nodered.org/t/raspberry-pi-modbus-tcp-port-502-not-listening/4625/14 "2018-11-08T17:54:31Z")

</div>

What is the device you are trying to connect to, and can you point to some docs that say how to use it as a modbus tcp server?
