String Decode Function

This should give you a start.

Basically extract the posts from the string in a function node, use parseInt were necessary to convert strings to numbers (search JavaScript parseInt for help on converting hex string parts to numbers)

var data = msg.payload;
var pl ={};//make new empty object

//Now populate the object with values
pl.data = data;//keep copy of original data. Handy for debugging
pl.stnNo = parseInt(data.substr(1,2));
pl.cmd = data.substr(3,2);
//... And so on

// Set payload to our new object
msg.payload = pl;
return msg;//return it to next node

So put that ^ in a function node, fill out the rest of the pl object properties, add a debug node & check it's all correctly split up.

1 Like