# Socketcan results

**URL:** <https://discourse.nodered.org/t/socketcan-results/76949>\
**Category:** General\
**Created:** [26 March 2023 06:35 UTC](https://discourse.nodered.org/t/socketcan-results/76949 "2023-03-26T06:35:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phoenix](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@Phoenix](https://discourse.nodered.org/u/Phoenix)\
**Post date:** [26 March 2023 06:35 UTC](https://discourse.nodered.org/t/socketcan-results/76949/1 "2023-03-26T06:35:19Z")

</div>

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:

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

---

<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:** [26 March 2023 08:20 UTC](https://discourse.nodered.org/t/socketcan-results/76949/2 "2023-03-26T08:20:44Z")

</div>

> [@Phoenix](#):
>
> 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)

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

Example:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/898302b5a7cd29522521c62ebd979d6eeb2b4352.png)

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Phoenix](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@Phoenix](https://discourse.nodered.org/u/Phoenix)\
**Post date:** [27 March 2023 06:04 UTC](https://discourse.nodered.org/t/socketcan-results/76949/3 "2023-03-27T06:04:00Z")

</div>

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.

```auto
[
    {
        "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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/671dfdbf6b97dc39a475d07efc23e3a12e9c9118.png)  
 ![Screenshot 2023-03-27 080207](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac0b676e131826e95e6c93046b2e6158b4fe9f0e.png)

Thanks  
BR

---

<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:** [26 May 2023 06:04 UTC](https://discourse.nodered.org/t/socketcan-results/76949/4 "2023-05-26T06:04:02Z")

</div>

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