# Send data using modbus tcp protocol from node-red to a PLC

**URL:** https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321
**Category:** General
**Tags:** modbus
**Created:** [24 June 2022 08:06 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321 "2022-06-24T08:06:10Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 08:06 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/1 "2022-06-24T08:06:10Z")

</div>

Hello,

I would like to send data using modbus tcp protocol from node-red to a PLC.  
it is possible to create a modbus TCP server on the node-red?

---

<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 June 2022 08:21 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/2 "2022-06-24T08:21:51Z")

</div>

> [@samirovic](#):
>
> it is possible to create a modbus TCP server on the node-red

Yes.

node-red-contrib-modbus has a built in example...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04161a1a004464367b94672da06bd138769a7310.png)

---

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 09:27 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/3 "2022-06-24T09:27:17Z")

</div>

in fact I'm new to node-red, the goal is to send data on the photo to an automaton. I couldn't do that with the example.

 ![node-red1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/431db659fffac1eb667418335de4da5c86dd6af1.png)  
 ![node-red2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f21e6315bea9bbd0f889ce067339f0ea194c2db.png)  
can you please help me to do this

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [24 June 2022 09:45 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/4 "2022-06-24T09:45:23Z")

</div>

I know nothing about modbus - is it a bus that is modded?

the screenshot above is the result from this discussion. (may help others getting this answered)

> [@Retrieve HTTP POST cUrl data on node-red](https://discourse.nodered.org/t/retrieve-http-post-curl-data-on-node-red/64266/14):
>
> I want to get the value in bold {"id":7,"model":"UR32","pn":"L04EU2211110FR0000000000","oem":"0000","rtver":"32.3.0.5","status":0,"result":[{"get":[{"type":"yruo\_cell\_status","index":0,"value":{"modem":{"modem\_status":"No SIM Card","model":"EC25","version":"EC25EUXGAR08A03M1G","cur\_sim":"SIM1","signal":"0asu (-113dBm)","register":"Not registered","imsi":"","iccid":"","net\_provider":"","net\_type":"","plmnid":"","lac":"0","cellid":"0","imei":"862506049149928"},"network":{"status":"Disconnected","…

---

<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 June 2022 10:07 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/5 "2022-06-24T10:07:37Z")

</div>

> [@samirovic](#):
>
> the goal is to send data on the photo to an automaton

What do you mean by sending it to an automation? If you mean that you want to write it to a PLC using modbus then the modbus node is the one to use. Do you understand the fundamentals of modbus?

---

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 12:44 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/6 "2022-06-24T12:44:40Z")

</div>

I managed to create the modbus server but when I set the port to 502, the node-red stops and it shows me this error message.

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/235acf4333798facb08c9cf91e4aa66c3d29d9ea.png)

---

<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 June 2022 12:51 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/7 "2022-06-24T12:51:45Z")

</div>

> [@samirovic](#):
>
> I managed to create the modbus server

The modbus server is the PLC. Node red is the client. Unless I misunderstand exactly what you are trying to do.

The reason for the error is that you are trying to listen on port 502 and ports below 1000 can only be listened to with root privileges. Why are you creating a server?

---

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 13:02 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/8 "2022-06-24T13:02:24Z")

</div>

yes I was wrong in fact the server is the PLC and node-red is the client.  
I created the server to upload data to the PLC.  
on the PLC I cannot change the port 502 tcp because it is the only port that it uses port the modbus TCP.  
what can i do for root privileges?

---

<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 June 2022 13:11 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/9 "2022-06-24T13:11:24Z")

</div>

> [@samirovic](#):
>
> what can i do for root privileges

Search the forum and internet (e.g. [here](https://gprivate.com/5zny6) )- asked and answered many times.

---

<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 June 2022 13:41 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/10 "2022-06-24T13:41:53Z")

</div>

> [@samirovic](#):
>
> I created the server to upload data to the PLC

Sorry, I still don't understand. Node red is the client, which can write to the (server) PLC using modbus. Why do you want to create a server?

You don't need root privileges to connect to the PLC with node-red as a client, only if you want node-red to be the server.

---

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 14:03 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/11 "2022-06-24T14:03:34Z")

</div>

here is the idea :

 ![Test2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/467fadb77db0c07d8fb3a7ac8d610a709a9b9c95.png)

---

<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 June 2022 14:19 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/12 "2022-06-24T14:19:59Z")

</div>

Sorry, that tells me nothing about why you want node-red to be a modbus server. Also I don't see a PLC in there.

---

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 14:27 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/13 "2022-06-24T14:27:44Z")

</div>

how am I going to upload the modbus data to the PLC if I am not using modbus server. the PLC is in the cloud

---

<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 June 2022 14:32 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/15 "2022-06-24T14:32:03Z")

</div>

Perhaps I am completely misunderstanding what you are trying to do. What is the data that you are trying to upload to the PLC in the cloud? Are you attempting to write to modbus registers just like a normal PLC? If so then the PLC is the server and node red is the client.

---

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 14:40 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/16 "2022-06-24T14:40:13Z")

</div>

in fact I want to upload data from a router (data consumption) I retrieve them in HTTP POST, I use Modbus because there is no other way to upload this data to the PLC

```auto
[
    {
        "id": "be09724a5e928145",
        "type": "tab",
        "label": "HTTP POST ",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8b03ba66b044c3d7",
        "type": "exec",
        "z": "be09724a5e928145",
        "command": "/usr/bin/curl ",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "2",
        "winHide": false,
        "oldrc": false,
        "name": "Curl",
        "x": 550,
        "y": 360,
        "wires": [
            [
                "570c1643b0bde49f"
            ],
            [],
            []
        ]
    },
    {
        "id": "f454c6183b821c86",
        "type": "inject",
        "z": "be09724a5e928145",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 360,
        "wires": [
            [
                "8fa43d6b7c972b98"
            ]
        ]
    },
    {
        "id": "8fa43d6b7c972b98",
        "type": "function",
        "z": "be09724a5e928145",
        "name": "Pass Args",
        "func": "msg.payload = '-H \"Content-Type:application/x-www-form-urlencoded\" -c ./cookie.txt -X POST --data \\'{\"id\":\"1\",\"execute\":1,\"core\" :\"user\",\"function\":\"login\",\"values\":[{\"username\":\"admin\",\"password\":\"ALtQvoiXntM7Cd3FcSa38g==\"}]}\\' http://10.90.9.37/cgi'\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 360,
        "wires": [
            [
                "8b03ba66b044c3d7"
            ]
        ]
    },
    {
        "id": "570c1643b0bde49f",
        "type": "debug",
        "z": "be09724a5e928145",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 750,
        "y": 360,
        "wires": []
    },
    {
        "id": "4b8b50db5297dac2",
        "type": "exec",
        "z": "be09724a5e928145",
        "command": "/usr/bin/curl ",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "2",
        "winHide": false,
        "oldrc": false,
        "name": "Curl",
        "x": 550,
        "y": 460,
        "wires": [
            [
                "3ba7a051ff679cf5"
            ],
            [],
            []
        ]
    },
    {
        "id": "1a6e2d34cb682e97",
        "type": "inject",
        "z": "be09724a5e928145",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 460,
        "wires": [
            [
                "fb72ee2237ade2bd"
            ]
        ]
    },
    {
        "id": "fb72ee2237ade2bd",
        "type": "function",
        "z": "be09724a5e928145",
        "name": "Pass Args",
        "func": "msg.payload = '-H \"Content-Type:application/x-www-form-urlencoded\" -b ./cookie.txt -X POST --data \\'{\"id\":7,\"execute\":1,\"core\":\"yruo_status\",\"function\":\"get\",\"values\":[{\"base\":\"yruo_celluar\"}]}\\' http://10.90.9.37/cgi'\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 460,
        "wires": [
            [
                "4b8b50db5297dac2"
            ]
        ]
    },
    {
        "id": "3ba7a051ff679cf5",
        "type": "json",
        "z": "be09724a5e928145",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 690,
        "y": 460,
        "wires": [
            [
                "1949b76c1cd2a229"
            ]
        ]
    },
    {
        "id": "1949b76c1cd2a229",
        "type": "function",
        "z": "be09724a5e928145",
        "name": "",
        "func": "const Value = msg.payload.result[0].get[0].value.statistics.sim2\nmsg.payload = Value.split(\":\")[3].trim()\nmsg.payload = msg.payload.split(\" \")[0]\nmsg.payload = Number(msg.payload);\nmsg.payload = {\n 'value': msg.payload, \n 'register': 'holding', \n 'address': 1 , \n 'disableMsgOutput' : 0 \n}; \n\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 840,
        "y": 460,
        "wires": [
            [
                "1c36643f8310e384"
            ]
        ]
    },
    {
        "id": "1c36643f8310e384",
        "type": "modbus-server",
        "z": "be09724a5e928145",
        "name": "",
        "logEnabled": false,
        "hostname": "192.168.1.101",
        "serverPort": "502",
        "responseDelay": 100,
        "delayUnit": "ms",
        "coilsBufferSize": "10",
        "holdingBufferSize": "10",
        "inputBufferSize": "10",
        "discreteBufferSize": "10",
        "showErrors": false,
        "x": 1060,
        "y": 460,
        "wires": [
            [
                "7663234554a528d0"
            ],
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "7663234554a528d0",
        "type": "debug",
        "z": "be09724a5e928145",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1250,
        "y": 480,
        "wires": []
    }
]

```

---

<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 June 2022 14:44 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/17 "2022-06-24T14:44:44Z")

</div>

> [@samirovic](#):
>
> I use Modbus because there is no other way to upload this data to the PLC

You didn't answer the question. You say you are using modbus. Are you using, for example, modbus write register to write data? If so you need to send a modbus write register command with the data. Where is the data being written to (so where is the register). If the register is in the cloud then the cloud is the server and node red is the client, writing the data to the cloud.

---

<div class="post-metadata">

### Author: ![samirovic](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@samirovic](https://discourse.nodered.org/u/samirovic)
#### Post date: [24 June 2022 15:08 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/18 "2022-06-24T15:08:59Z")

</div>

yes i use modbus write register to write data

---

<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 June 2022 15:20 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/19 "2022-06-24T15:20:42Z")

</div>

> [@samirovic](#):
>
> i use modbus write register to write data

Where is the data being written to and by what? If it is being written to the PLC in the cloud by node-red then node red is the client, and you should be using the modbus write node to do that, and not configuring a modbus server in node red.

The modbus server in node red is for when you want node-red to behave like a PLC, so other clients can write to registers in node-red.

---

<div class="post-metadata">

### Author: ![tonylane26](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonylane26/32/9272_2.png) [@tonylane26](https://discourse.nodered.org/u/tonylane26)
#### Post date: [27 June 2022 12:59 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/20 "2022-06-27T12:59:47Z")

</div>

I have a lot more experience with PLCs and Modbus than with Node-Red, although I do have a Modbus TCP connection from a Node-Red device (Raspberry Pi) to a PLC/HMI so...

The older Modbus documentation, especially for PLCs, refers to systems comprising "Modbus Masters" and "Modbus Slaves". A PLC can be Master or Slave, and actually can be both at the same time. If you PLC refers to data mapped as Registers 40000-40100 for example, your PLC is acting as Modbus Slave.

A Modbus Master sends a request/command to a Slave, and the Slave responds, either returning the requested data or executing a Write command.  
In line with modern definitions:  
Modbus Master = Client and  
Modbus Slave = Server.

The Server (Slave) is passive, creating a space comprising multiple Modbus "Registers" which can be Bits or Words (16 bit). Since Modbus is an open standard there are hundreds of variations to include double Words (32 bit) and Floats (in 32 bit).

The Clients (Masters) actively poll the Server, either to retrieve data (Registers) or to write data in the Server.

To do any and all of this in Node-Red, just install the node-red-contrib-modbus and you're ready to go. You shouldn't have to worry about permissions etc. The Host Server you specify in your Client-Nodes will almost certainly to Port 502, but that is the port the Server is listening on, NOT the port on your client.

Anything else you want to know about Modbus can be found here... [https://modbus.org/](https://modbus.org/)  
Hope this helps!

---

<div class="post-metadata">

### Author: ![Tommy1](https://avatars.discourse-cdn.com/v4/letter/t/e47774/32.png) [@Tommy1](https://discourse.nodered.org/u/Tommy1)
#### Post date: [29 June 2022 13:05 UTC](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321/21 "2022-06-29T13:05:41Z")

</div>

I dont think you can send (photos) over modbus as the format of modbus is 16 / 32 bit intergers. if you want to write a register to the plc, as long as its setup in the tag list (in the plc) you just do a write with the flow and the value you want to change IE %mw0 = 6789 and it will change that register in the PLC.

Tommy

[Next page](https://discourse.nodered.org/t/send-data-using-modbus-tcp-protocol-from-node-red-to-a-plc/64321.md?page=2)
