Help with converting string to hex array

Hi all please can someone help me with a conversion problem

my incomming data from serial port looks like this.
Screenshot 2022-07-14 131314
i have been able to break it up into the correct values and place in an array which im happy with
Screenshot 2022-07-14 131359
however node red cannot convert the hex value to a readable number as the format is not correct
"0DD2" when it should be "0x0DD2" telling the system that it is a 16bit hex number.

msg.payload=parseInt("0DD2", 16); should work

Depending how you slice the string now, the above can be done during slicing.

that worked partially . but it has replaced all the data with 0dd2. defanitly a step in the right direction
Screenshot 2022-07-14 135218

If you have node-red-contrib-buffer parser, you can do pretty much anything you need. I imagine you actually want real numbers (not hex strings - but you can have thos too) e.g...

image

flow...

[{"id":"a4466e01f63dcff8","type":"inject","z":"8fb7704d922a7884","name":"03051234eeffabcd32109999","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"03051234eeffabcd32109999","payloadType":"str","x":280,"y":680,"wires":[["bd0bcb99df2b12f3"]]},{"id":"6cdb292d19b218ca","type":"debug","z":"8fb7704d922a7884","name":"debug 47","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":680,"wires":[]},{"id":"bd0bcb99df2b12f3","type":"buffer-parser","z":"8fb7704d922a7884","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"buffer","name":"asBuffer","offset":0,"length":-1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"int16be","offset":0,"length":-1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16le","name":"uint16be","offset":0,"length":-1,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"str0","offset":0,"length":2,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"str1","offset":2,"length":2,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"str2","offset":4,"length":2,"offsetbit":0,"scale":"1","mask":""},{"type":"hex","name":"str3","offset":6,"length":2,"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":510,"y":680,"wires":[["6cdb292d19b218ca"]]}]

hi guys just got it working with a small change to edje11 code now it works well . i have been fighting with this number for 4 days now .

msg.payload=parseInt(msg.payload, 16); this works between the split and join nodes.

Btw i love your buffer passer node i use it for everything however when i pass this number through it i get
Screenshot 2022-07-14 140703

with that function node it comes out like this
Screenshot 2022-07-14 140757 which is correct for what im trying to do then off to the buffer parser node to name everything and off to influx.

thanks for the help much app

could you copy the data that was going into the buffer parser (add a debug node & use the Copy Value button on the debug message in the debug sidebar to grab the value)

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