Node Red socketcan output frame received problem

Hello,
I am working on a node red project that uses sockectcan out.
I have a problem when receiving a frame.
I receive a data frame containing 2 separate bytes, example "0x1004". When I receive it, I get 0x104, which is annoying because the zero of the byte "0x04" is deleted.
How can I receive the correct data frame without the zero being erased?
Thanks a lot.

Welcome to the forum @David321

Please feed the data you are receiving into a Debug node and show us what you see. Then we can be sure exactly what form the data is in. You can paste a screenshot here.
Also tell us what you want to do with that data.

I believe you're working with the array msg.payload.data?

We are doing something like msg.payload.data[i].toString(16).padStart(2, '0'); to get leading zeros.

the frame represents a voltage value.
This is what i put in sockecan in :
image

When I send the frame 0x0410, which corresponds to 41V, in the socketcan in,
I receive the frame 0x410 at the output of the socketcan out, which causes a problem because the voltage value is not the same. So I would like to receive 0x0410 at the output of the socketcan out
This is what i received in socketcan out :
image

You havent shown us how you are extracting the data (though I can guess where you are going wrong)

You can use buffer-parser for these kind of conversions.

I have also added a DIY function for comparison...

Demo flow (use CTRL+I to import)

[{"id":"5cc7cc13ae146210","type":"inject","z":"3ce7b2dfd0389010","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"000C0300#20010410","payloadType":"str","x":1560,"y":580,"wires":[["62f29b073ef65185"]]},{"id":"62f29b073ef65185","type":"function","z":"3ce7b2dfd0389010","name":"remove data before #","func":"const parts = msg.payload.split('#')\nmsg.payload = parts[1]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1800,"y":580,"wires":[["85240c9841bd2da2","7e296ef1a5b95560"]]},{"id":"85240c9841bd2da2","type":"function","z":"3ce7b2dfd0389010","name":"get value","func":"const buf = Buffer.from(msg.payload,\"hex\")\nmsg.payload = {\n    item1: buf.readUint16LE(0) / 100,\n    voltage: buf.readUint16LE(2) / 100,\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2000,"y":580,"wires":[["0a5ca2d32ff6c518"]]},{"id":"7e296ef1a5b95560","type":"buffer-parser","z":"3ce7b2dfd0389010","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16le","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"/ 100","mask":""},{"type":"uint16le","name":"voltage","offset":2,"length":1,"offsetbit":0,"scale":"/ 100","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":2010,"y":640,"wires":[["8a662f13e58752d0"]]},{"id":"0a5ca2d32ff6c518","type":"debug","z":"3ce7b2dfd0389010","name":"debug 157","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2160,"y":580,"wires":[]},{"id":"8a662f13e58752d0","type":"debug","z":"3ce7b2dfd0389010","name":"debug 158","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2180,"y":640,"wires":[]}]

I solved the problem thank to you.
Thank you a lot.
Have a nice day !

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