Please inquire about converting numbers.
Here is the buffered value.
[1,3,10,1,4] > msg.payload
Create a new buffer and truncate the item located at [3],[4]
var pay1= Buffer.alloc(2);
pay1[0]=msg.payload[3].slice(0,2)
pay1[0]=msg.payload[4].slice(0,2)
Then slice it again and turn it into a string.
var pay2=pay1.slice(0,4).toString('hex');
Then you get something like this:
"0104"
So we convert this value to a number.
var pay3=Number(pay2);
Then it comes out in numeric form.
It comes out as 104 or 0x68.
the value i want is
It should come out as 0x104, the number 260.
But I keep getting 104 or 0x68.
Is there any way to solve this?
The code is organized as follows.
buffer [1,3,10,1,4]
var pay1= Buffer.alloc(2);
pay1[0]=msg.payload[3].slice(0,2);
pay1[0]=msg.payload[4].slice(0,2);
var pay2=pay1.slice(0,4).toString('hex');
var pay3=Number(pay2);
msg.payload=pay3;
return msg;