I want to split a hex string and work on each part separately, if i have a string such as "00D7FD0000280001" id like to be able split it out into 4 bytes. Any resources anyone can point me to?
Thanks
I want to split a hex string and work on each part separately, if i have a string such as "00D7FD0000280001" id like to be able split it out into 4 bytes. Any resources anyone can point me to?
Thanks
Here is one way you could do it. Since a string can be treated as an array you could do
let str = msg.payload;
let part1 = str[0] + str[1] + str[2] + str[3]
msg.payload = part1
return msg;
Here is a small flow example:
[{"id":"28f3db305ae1d0da","type":"inject","z":"c2a7ae641f1483bf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"00D7FD0000280001","payloadType":"str","x":150,"y":160,"wires":[["c349423ce597fe93"]]},{"id":"c349423ce597fe93","type":"function","z":"c2a7ae641f1483bf","name":"function 5","func":"let str = msg.payload;\nlet part1 = str[0] + str[1] + str[2] + str[3]\nmsg.payload = part1\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":160,"wires":[["087cedc91da944ac"]]},{"id":"087cedc91da944ac","type":"debug","z":"c2a7ae641f1483bf","name":"debug 43","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":160,"wires":[]}]
I'll let you finish the rest
Thank you, I will try that.
The is a low code node built for this...
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.