Write to subregister via Modbus and bufferparser part II

Hello friends. Since i am working with MODBUS and wrtting to subregisters, i have already had my challenges with it. Unfortunately i faced a problem again but the thread is alreay closed. If someone is interested, here is part I: Write to subregister via Modbus and bufferparser

My problem right now: I reorganized my dashboard a bit. To conrol my dosing pump is use dropdown widgets now instead of a form. I now want to write to an adress that is "devided" into subadresses (bits) (see part I).

Since i swicthed to dropdown widgets i am not able to control my pump (subadresses) correctly.
My flow is very similiar to the solution of part I, but somehow i am missing something that it doesnt work.
The problem: My changes in my dashboard arent correctly assigned to the subadresses.

Here is the flow:

[
    {
        "id": "5a7829451f9063b3",
        "type": "mqtt in",
        "z": "d51b33bb70359ba8",
        "name": "",
        "topic": "CIM500/W_Remote",
        "qos": "2",
        "datatype": "json",
        "broker": "b6502b0e06f48d91",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 120,
        "y": 1460,
        "wires": [
            [
                "55b6160814f8758c",
                "3564a658c51b7aaa"
            ]
        ]
    },
    {
        "id": "234225ae85511c6b",
        "type": "mqtt in",
        "z": "d51b33bb70359ba8",
        "name": "",
        "topic": "CIM500/W_Deaerating",
        "qos": "2",
        "datatype": "json",
        "broker": "b6502b0e06f48d91",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 1520,
        "wires": [
            [
                "55b6160814f8758c"
            ]
        ]
    },
    {
        "id": "27be8f062001d1bc",
        "type": "mqtt in",
        "z": "d51b33bb70359ba8",
        "name": "",
        "topic": "CIM500/W_AnalogMode",
        "qos": "2",
        "datatype": "json",
        "broker": "b6502b0e06f48d91",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 1580,
        "wires": [
            [
                "55b6160814f8758c"
            ]
        ]
    },
    {
        "id": "128d48bbce316a29",
        "type": "mqtt in",
        "z": "d51b33bb70359ba8",
        "name": "",
        "topic": "CIM500/W_TimerMode",
        "qos": "2",
        "datatype": "json",
        "broker": "b6502b0e06f48d91",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 1640,
        "wires": [
            [
                "55b6160814f8758c"
            ]
        ]
    },
    {
        "id": "f4652b418976bc2c",
        "type": "mqtt in",
        "z": "d51b33bb70359ba8",
        "name": "",
        "topic": "CIM500/W_SlowMode",
        "qos": "2",
        "datatype": "json",
        "broker": "b6502b0e06f48d91",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 1700,
        "wires": [
            [
                "55b6160814f8758c"
            ]
        ]
    },
    {
        "id": "b78222eb15acebd2",
        "type": "mqtt in",
        "z": "d51b33bb70359ba8",
        "name": "",
        "topic": "CIM500/W_Velocity",
        "qos": "2",
        "datatype": "json",
        "broker": "b6502b0e06f48d91",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 120,
        "y": 1760,
        "wires": [
            [
                "55b6160814f8758c"
            ]
        ]
    },
    {
        "id": "1648883a3db1bf35",
        "type": "debug",
        "z": "d51b33bb70359ba8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 490,
        "y": 1500,
        "wires": []
    },
    {
        "id": "2a121dacf61440d3",
        "type": "modbus-flex-getter",
        "z": "d51b33bb70359ba8",
        "name": "",
        "showStatusActivities": true,
        "showErrors": true,
        "logIOActivities": false,
        "server": "0e3ec676f3e39293",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "x": 1380,
        "y": 1600,
        "wires": [
            [
                "c6bcda69ef6aa266",
                "2075044623096f3e"
            ],
            []
        ]
    },
    {
        "id": "c6bcda69ef6aa266",
        "type": "modbus-response",
        "z": "d51b33bb70359ba8",
        "name": "",
        "registerShowMax": 20,
        "x": 1370,
        "y": 1540,
        "wires": []
    },
    {
        "id": "c4c1f47bd24a8118",
        "type": "function",
        "z": "d51b33bb70359ba8",
        "name": "Read_101",
        "func": "msg.payload =\n{\n    value: msg.payload,\n    'fc': 3,\n    'unitid': 1,\n    'address': 100,\n    'quantity': 1\n\n};\nreturn msg",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1150,
        "y": 1560,
        "wires": [
            [
                "2a121dacf61440d3"
            ]
        ]
    },
    {
        "id": "ea2e244d77b54dfc",
        "type": "inject",
        "z": "d51b33bb70359ba8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 960,
        "y": 1560,
        "wires": [
            [
                "c4c1f47bd24a8118"
            ]
        ]
    },
    {
        "id": "2075044623096f3e",
        "type": "buffer-parser",
        "z": "d51b33bb70359ba8",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "bool",
                "name": "Remote ",
                "offset": 1,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "Deaerating ",
                "offset": 1,
                "length": 1,
                "offsetbit": 1,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "AnalogMode ",
                "offset": 1,
                "length": 1,
                "offsetbit": 2,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "TimerMode ",
                "offset": 1,
                "length": 1,
                "offsetbit": 3,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "SlowMode ",
                "offset": 1,
                "length": 1,
                "offsetbit": 4,
                "scale": "1",
                "mask": ""
            },
            {
                "type": "bool",
                "name": "Velocity",
                "offset": 1,
                "length": 1,
                "offsetbit": 5,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 1590,
        "y": 1620,
        "wires": [
            [
                "9018aad8437a1df9"
            ]
        ]
    },
    {
        "id": "7e084d181f53a1e5",
        "type": "debug",
        "z": "d51b33bb70359ba8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1980,
        "y": 1620,
        "wires": []
    },
    {
        "id": "9018aad8437a1df9",
        "type": "change",
        "z": "d51b33bb70359ba8",
        "name": "save to Context",
        "rules": [
            {
                "t": "set",
                "p": "Status_ADR_201",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1780,
        "y": 1620,
        "wires": [
            [
                "7e084d181f53a1e5"
            ]
        ]
    },
    {
        "id": "55b6160814f8758c",
        "type": "function",
        "z": "d51b33bb70359ba8",
        "name": "update Context",
        "func": "let ps = flow.get(\"Status_ADR_201\")\n\nps = [[ps.Remote, ps.Deaerating, ps.AnalogMode, ps.TimerMode, ps.SlowMode, ps.Velocity, false, false]]\n\nif (msg.topic === \"CIM500/W_Remote\") {\n    ps[0][0] = msg.payload\n}\nelse if (msg.topic === \"CIM500/W_Deaerating\") {\n    ps[0][1] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_AnalogMode\") {\n    ps[0][2] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_TimerMode\") {\n    ps[0][3] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_SlowMode\") {\n    ps[0][4] = msg.payload;\n}\nelse if (msg.topic === \"CIM500/W_Velocity\") {\n    ps[0][5] = msg.payload;\n}\n\nmsg.payload = ps;\n\nreturn msg;\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 1620,
        "wires": [
            [
                "1648883a3db1bf35",
                "f3d5278d76a3efc8"
            ]
        ]
    },
    {
        "id": "97cde1fad3844454",
        "type": "link out",
        "z": "d51b33bb70359ba8",
        "name": "link out 1",
        "mode": "link",
        "links": [
            "11b737836169d245"
        ],
        "x": 1355,
        "y": 1760,
        "wires": []
    },
    {
        "id": "11b737836169d245",
        "type": "link in",
        "z": "d51b33bb70359ba8",
        "name": "link in 1",
        "links": [
            "97cde1fad3844454"
        ],
        "x": 955,
        "y": 1480,
        "wires": [
            [
                "c4c1f47bd24a8118"
            ]
        ]
    },
    {
        "id": "f3d5278d76a3efc8",
        "type": "buffer-maker",
        "z": "d51b33bb70359ba8",
        "name": "",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "name": "item",
                "type": "16bitbe",
                "length": 1,
                "dataType": "msg",
                "data": "payload"
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "x": 570,
        "y": 1740,
        "wires": [
            [
                "457614cebc939e09",
                "fd89bfdde05f1236"
            ]
        ]
    },
    {
        "id": "457614cebc939e09",
        "type": "buffer-parser",
        "z": "d51b33bb70359ba8",
        "name": "",
        "data": "payload",
        "dataType": "msg",
        "specification": "spec",
        "specificationType": "ui",
        "items": [
            {
                "type": "uint16be",
                "name": "decimal",
                "offset": 0,
                "length": 1,
                "offsetbit": 0,
                "scale": "1",
                "mask": ""
            }
        ],
        "swap1": "",
        "swap2": "",
        "swap3": "",
        "swap1Type": "swap",
        "swap2Type": "swap",
        "swap3Type": "swap",
        "msgProperty": "payload",
        "msgPropertyType": "str",
        "resultType": "keyvalue",
        "resultTypeType": "return",
        "multipleResult": false,
        "fanOutMultipleResult": false,
        "setTopic": true,
        "outputs": 1,
        "x": 750,
        "y": 1740,
        "wires": [
            [
                "fed0774c11d23fdd",
                "a0c6618067b04d11"
            ]
        ]
    },
    {
        "id": "fd89bfdde05f1236",
        "type": "debug",
        "z": "d51b33bb70359ba8",
        "name": "debug 2",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 1680,
        "wires": []
    },
    {
        "id": "fed0774c11d23fdd",
        "type": "debug",
        "z": "d51b33bb70359ba8",
        "name": "debug 3",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 920,
        "y": 1700,
        "wires": []
    },
    {
        "id": "a0c6618067b04d11",
        "type": "function",
        "z": "d51b33bb70359ba8",
        "name": "modbus",
        "func": "var fc = 6;\nvar sa = 100;\nvar addresses = 1;\nvar value = msg.payload.decimal;  // value calculated from buffer-parser\nmsg.slave_ip = \"10.240.6.39\";\n\nmsg.payload = { \"value\": value, 'fc': fc, 'unitid': 1, 'address': sa, 'quantity': addresses };\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 920,
        "y": 1740,
        "wires": [
            [
                "82caf85a77844c03",
                "ec2ea67e459f4d21"
            ]
        ]
    },
    {
        "id": "ec2ea67e459f4d21",
        "type": "debug",
        "z": "d51b33bb70359ba8",
        "name": "debug 4",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1140,
        "y": 1680,
        "wires": []
    },
    {
        "id": "82caf85a77844c03",
        "type": "modbus-flex-write",
        "z": "d51b33bb70359ba8",
        "name": "",
        "showStatusActivities": true,
        "showErrors": true,
        "server": "0e3ec676f3e39293",
        "emptyMsgOnFail": false,
        "keepMsgProperties": false,
        "x": 1160,
        "y": 1740,
        "wires": [
            [
                "97cde1fad3844454"
            ],
            []
        ]
    },
    {
        "id": "3564a658c51b7aaa",
        "type": "debug",
        "z": "d51b33bb70359ba8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 360,
        "y": 1420,
        "wires": []
    },
    {
        "id": "b6502b0e06f48d91",
        "type": "mqtt-broker",
        "name": "",
        "broker": "185.164.7.227",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "0e3ec676f3e39293",
        "type": "modbus-client",
        "name": "CIM500",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "tcpHost": "10.240.6.39",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "0x3A",
        "unit_id": "1",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectOnTimeout": true,
        "reconnectTimeout": "2000",
        "parallelUnitIdsAllowed": true
    }
]

Hello Manuel ..

since we dont have access to your mqtt ..
can you show us how the msgs arriving at the mqtt nodes look like ?
is the msg.payload a boolean true false value or something else ?

I am sorry, there was a mistake in my mqtt server..

Realy sorry and thank you for replying.

Is there a way to delete thhis thread?

best regards

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