# Modbus via websocket

**URL:** <https://discourse.nodered.org/t/modbus-via-websocket/79459>\
**Category:** General\
**Created:** [28 June 2023 08:37 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459 "2023-06-28T08:37:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivdoke39](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shivdoke39/32/80788_2.png) [@Shivdoke39](https://discourse.nodered.org/u/Shivdoke39)\
**Post date:** [28 June 2023 08:37 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/1 "2023-06-28T08:37:50Z")

</div>

hello, is there any way or sample flow to understand , how to write and read modbus regsiter using websocket protocol..

---

<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:** [28 June 2023 09:20 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/2 "2023-06-28T09:20:09Z")

</div>

Hi.

I do not know of any devices that natively support websockets so it is not clear what your goal is & you will need to provide more detail

For example: where does the websocket, modbus client and modbus server fit in all of this?

---

<div class="post-metadata">

**Author:** ![Shivdoke39](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shivdoke39/32/80788_2.png) [@Shivdoke39](https://discourse.nodered.org/u/Shivdoke39)\
**Post date:** [28 June 2023 09:59 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/3 "2023-06-28T09:59:22Z")

</div>

```auto
[
    {
        "id": "b3dbcbc156a00bf9",
        "type": "tab",
        "label": "Flow 10",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b23393c0977eb356",
        "type": "websocket in",
        "z": "b3dbcbc156a00bf9",
        "name": "WebSocket In",
        "server": "0b86a425d9ba3c0c",
        "client": "",
        "x": 190,
        "y": 340,
        "wires": [
            [
                "512eb61d159733e7"
            ]
        ]
    },
    {
        "id": "512eb61d159733e7",
        "type": "modbus-write",
        "z": "b3dbcbc156a00bf9",
        "name": "Modbus Write",
        "showStatusActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "0",
        "quantity": "1",
        "server": "003c1045fbe7a529",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "delayOnStart": false,
        "startDelayTime": "",
        "x": 440,
        "y": 300,
        "wires": [
            [
                "deb1b75bf0e958b9",
                "f6d5e02b40ccdc21"
            ],
            [
                "a5f6feb657c97e1d"
            ]
        ]
    },
    {
        "id": "deb1b75bf0e958b9",
        "type": "websocket out",
        "z": "b3dbcbc156a00bf9",
        "name": "WebSocket Out",
        "server": "",
        "client": "2ecd3b7d5b75385d",
        "x": 760,
        "y": 280,
        "wires": []
    },
    {
        "id": "f6d5e02b40ccdc21",
        "type": "debug",
        "z": "b3dbcbc156a00bf9",
        "name": "Debug",
        "active": true,
        "x": 790,
        "y": 360,
        "wires": []
    },
    {
        "id": "7cbb388d2c7df990",
        "type": "modbus-server",
        "z": "b3dbcbc156a00bf9",
        "name": "",
        "logEnabled": false,
        "hostname": "localhost",
        "serverPort": 10502,
        "responseDelay": 100,
        "delayUnit": "ms",
        "coilsBufferSize": 10000,
        "holdingBufferSize": 10000,
        "inputBufferSize": 10000,
        "discreteBufferSize": 10000,
        "showErrors": false,
        "x": 400,
        "y": 120,
        "wires": [
            [
                "260256e3fa35d951"
            ],
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "619cdc7d6e713db4",
        "type": "inject",
        "z": "b3dbcbc156a00bf9",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 100,
        "wires": [
            [
                "7cbb388d2c7df990"
            ]
        ]
    },
    {
        "id": "260256e3fa35d951",
        "type": "debug",
        "z": "b3dbcbc156a00bf9",
        "name": "debug 41",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 80,
        "wires": []
    },
    {
        "id": "bdadedc21d3f9124",
        "type": "modbus-read",
        "z": "b3dbcbc156a00bf9",
        "name": "",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "showWarnings": true,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "1",
        "quantity": "4",
        "rate": "1",
        "rateUnit": "s",
        "delayOnStart": false,
        "startDelayTime": "",
        "server": "003c1045fbe7a529",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 350,
        "y": 500,
        "wires": [
            [
                "58453c322d1b605b"
            ],
            []
        ]
    },
    {
        "id": "58453c322d1b605b",
        "type": "modbus-response",
        "z": "b3dbcbc156a00bf9",
        "name": "",
        "registerShowMax": 20,
        "x": 650,
        "y": 520,
        "wires": []
    },
    {
        "id": "a5f6feb657c97e1d",
        "type": "debug",
        "z": "b3dbcbc156a00bf9",
        "name": "debug 42",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 420,
        "wires": []
    },
    {
        "id": "0b86a425d9ba3c0c",
        "type": "websocket-listener",
        "path": "/modbus",
        "wholemsg": "false"
    },
    {
        "id": "003c1045fbe7a529",
        "type": "modbus-client",
        "name": "Modbus Server",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": false,
        "tcpHost": "localhost",
        "tcpPort": "10502",
        "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
    },
    {
        "id": "2ecd3b7d5b75385d",
        "type": "websocket-client",
        "path": "/modbus",
        "tls": "",
        "wholemsg": "false",
        "hb": "0",
        "subprotocol": ""
    }
] 

```

_Admin edit: wrapped flow in three ````` backticks_

---

<div class="post-metadata">

**Author:** ![Shivdoke39](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shivdoke39/32/80788_2.png) [@Shivdoke39](https://discourse.nodered.org/u/Shivdoke39)\
**Post date:** [28 June 2023 10:11 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/4 "2023-06-28T10:11:19Z")

</div>

ws://your-node-red-server:port/modbus : url  
header : key : Sec-WebSocket-Protocol value :modbus  
data :01 03 00 00 00 02  
id fc addess value fomat

---

<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:** [28 June 2023 10:17 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/5 "2023-06-28T10:17:30Z")

</div>

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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:** [28 June 2023 10:18 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/6 "2023-06-28T10:18:37Z")

</div>

Before posting any flows, please explain the architecture as requested.

> [@Steve-Mcl](#):
>
> where does the websocket, modbus client and modbus server fit in all of this

Also, please provide node-red & nodejs versions

---

<div class="post-metadata">

**Author:** ![Shivdoke39](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shivdoke39/32/80788_2.png) [@Shivdoke39](https://discourse.nodered.org/u/Shivdoke39)\
**Post date:** [28 June 2023 10:20 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/7 "2023-06-28T10:20:57Z")

</div>

28 Jun 15:50:22 - [info] Node-RED version: v3.0.2  
28 Jun 15:50:22 - [info] Node.js version: v18.16.0

---

<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:** [28 June 2023 10:49 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/8 "2023-06-28T10:49:04Z")

</div>

Last try 🙂

> [@Steve-Mcl](#):
>
> Before posting any flows, please explain the architecture as requested.
> 
> > [@Steve-Mcl](#):
> >
> > where does the websocket, modbus client and modbus server fit in all of this

Please explain the architecture. A small drawing will help us to help you.

---

<div class="post-metadata">

**Author:** ![Shivdoke39](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shivdoke39/32/80788_2.png) [@Shivdoke39](https://discourse.nodered.org/u/Shivdoke39)\
**Post date:** [28 June 2023 11:00 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/9 "2023-06-28T11:00:27Z")

</div>

hello,  
i want to write modbus holding registers value using modbus write node and websocket .  
i have created a flow which consist local modbus server node . and websocket in node is connected to input of modbus write with all details (fc:3,unit id:1,address:0,quanttiy:2)... I am sending modbus values withhex format using postamn websocket with above data and header....  
im getting response message in debug node as all parameter but my adrress values is not changing or writing ..  
debug response " object

value: buffer[6][raw](http://localhost:1880/#)

0: 0x1  
1: 0x3  
2: 0x6  
3: 0x0  
4: 0x0  
5: 0x3  
unitid: "1"  
fc: 6  
address: 0  
quantity: "1"  
messageId: "649c11f64f66694ca190dc13"

---

<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:** [27 August 2023 11:00 UTC](https://discourse.nodered.org/t/modbus-via-websocket/79459/10 "2023-08-27T11:00:37Z")

</div>

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