Hello friends,
I'm a beginner, some simple flow I've already created and working on.
Now I would like to read data from the RS485 power meter concentrator. The data is loaded into a string that has 83 bytes. Data is in hex. Is here everything is OK.
I need to split the individual bytes from the string and save them to separate variables or array.
For example, four bytes from Byte (position) 11:
var NewArrayValue1 = msg.payload.string(11,4);
I read the forum, but I can not catch anything from which I would bounce off. Would you be nice and could I ask for advice? Thank you
It is generally better to copy/paste code rather than screenshot as it is easier for us to read and modify it. If you do that then put a line containing three backtick characters before the code and another after to stop the forum from reformatting it.
The first two lines are not required, they do nothing as you don't use the variable string and valArr1 is redifined later.
In your second example you would need something like var valArr1 = [msg.payload[11].toString(16), msg.payload[12].toString, ...]
and again the first two lines do nothing.
However, I think your first example is easier to read so personally I would probably stick with that, or maybe remove valArr1 completely and put
The + operator in JS concatenates strings, which is why you end up with that result.
A better way to approach this is to use the ArrayBuffer methods -- for instance, to convert bytes 11-14 of your input buffer to a signed 32-bit integer, you can use this code:
// read 4 bytes from input buffer, starting at offset=11
var myInt = msg.payload.readInt32BE(11); // returns 815005831
// replace the payload buffer with the value, and return the msg object
msg.payload = myInt;
return msg;
I would not like to create a new thread, so I write here.
I use the node Switch to forward messages to given outputs. In the header of each message there is a device ID on the byte 2 and byte 3 (Array[2,3]), according to which the messages are sent to the given outputs (ID1 = Out1, ID2 = Out2, etc.).
When I started a switch with one byte, the function worked correctly, but I can't set the function correctly to take 2 bytes as an ID. You would be kind and able to advise me
I convert values from buffer to string in the next step for individual dataloggers separately.
My idea was to forward the unmodified data from each datalogger to separate parts for further processing.