Raspberry Pi Modbus TCP, port 502 not listening


#1

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

[{"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/
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


#2

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?


#3

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?


#4

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

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.


#5

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.


#6

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


#7

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


#8

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

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


#9

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

"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)


#10

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


#11

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.


#12

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


#13

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


#14

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?