Socketcan results

Dear all, I am having some trouble reading the results from a SocketCan out.
First of all I am receiving also what I'm sending. Don't know why. How could I filter that?

Second is that the result is already in decimal. But to read the correct result, I need to combine the last 4 results into 1 HEX data and then transform to decimal (trying for 3 days).

Any idea is welcomed.
Below my results:

26.3.2023, 08:17:59   node: debug 1
msg.payload : Object
object
timestamp: 1679811479672
ext: false
canid: 1663
dlc: 4
rtr: false
data: array[4]
0: 64
1: 3
2: 32
3: 2


26.3.2023, 08:17:59   node: debug 1
msg.payload : Object
object
timestamp: 1679811479673
ext: false
canid: 1535
dlc: 8
rtr: false
data: array[8]
0: 67
1: 3
2: 32
3: 2
4: 231
5: 5
6: 0
7: 0

Thanks in advance.
BR

You can likely use node-red-contrib-buffer-parser.

Example:

However, since you have not stated the format of the data nor have you provided equivelent values for the data array you provided, it is pure guess work on my behalf - I have no idea if the values I have produced are what you expect.

Demo flow (import using CTRL-I)

[{"id":"7bb716b730bd660b","type":"inject","z":"edf82570772f4a51","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1245,"y":120,"wires":[["cd719cc34eff5df7"]],"l":false},{"id":"cd719cc34eff5df7","type":"function","z":"edf82570772f4a51","name":"Your data: canid=1535, dlc=8","func":"msg.payload = {\n    timestamp: 1679811479673,\n    ext: false,\n    canid: 1535,\n    dlc: 8,\n    rtr: false,\n    data: [67,3,32,2,231,5,0,0]\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1400,"y":120,"wires":[["3ff798b9fc5e960e"]]},{"id":"ac1073394cf6edca","type":"function","z":"edf82570772f4a51","name":"Your data: canid=1663, dlc=4","func":"msg.payload = {\n    timestamp: 1679811479672,\n    ext: false,\n    canid: 1663,\n    dlc: 4,\n    rtr: false,\n    data: [64,3,32,2]\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1400,"y":160,"wires":[["3ff798b9fc5e960e"]]},{"id":"6fd213678ebf8e1d","type":"inject","z":"edf82570772f4a51","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1245,"y":160,"wires":[["ac1073394cf6edca"]],"l":false},{"id":"3ff798b9fc5e960e","type":"buffer-maker","z":"edf82570772f4a51","name":"Array of bytes, to buffer","specification":"spec","specificationType":"ui","items":[{"name":"item1","type":"byte","length":-1,"dataType":"msg","data":"payload.data"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload.buffer","msgPropertyType":"str","x":1690,"y":140,"wires":[["3a6a26f0a95aac7f"]]},{"id":"3a6a26f0a95aac7f","type":"buffer-parser","z":"edf82570772f4a51","name":"Buffer to 32bit Decimals","data":"payload.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int32be","name":"values","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":1420,"y":220,"wires":[["66076f2c2c417fbd"]]},{"id":"66076f2c2c417fbd","type":"debug","z":"edf82570772f4a51","name":"debug 167","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1660,"y":220,"wires":[]}]

Hi there,
I've used a Switch to get only the incoming messages.
And for the transformation, a Change Node.
I'm pretty sure there are easier ways, but this was my solution.

[
    {
        "id": "9b4193b07c35310e",
        "type": "tab",
        "label": "Flow 4",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "1bcbcbb974957842",
        "type": "switch",
        "z": "9b4193b07c35310e",
        "name": "",
        "property": "payload.data[0]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "64",
                "vt": "num"
            },
            {
                "t": "neq",
                "v": "64",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 610,
        "y": 160,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "a5cbf5e1649c5307",
        "type": "change",
        "z": "9b4193b07c35310e",
        "name": "Total act power",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.data",
                "tot": "msg"
            },
            {
                "t": "delete",
                "p": "payload[0]",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload[0]",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload[0]",
                "pt": "msg"
            },
            {
                "t": "delete",
                "p": "payload[0]",
                "pt": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$round(\t(payload[3] *256*256*256+\tpayload[2] *256*256+\tpayload[1] *256+\tpayload[0])*0.01\t ,\t   4\t)\t",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 620,
        "y": 240,
        "wires": [
            []
        ]
    }
]

Screenshot 2023-03-27 080131
Screenshot 2023-03-27 080207

Thanks
BR

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