Modbus via websocket

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

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?

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

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

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

``` 
   code goes here 
```

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

See this post for more details - How to share code or flow json

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

Also, please provide node-red & nodejs versions

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

Last try :slight_smile:

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

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

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

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