Hi i need to send several requests to my heater, end i will sort his answer to the right output.
like:
The heater can handel max 4-5 requests in 1 Buffer, so i have to split the requests.
In my function i try to search with a "for each loop" the Hex byte, that for example "0x0d" Boiler.
Then i try to read the next byte "readUInt16BE", witch are the temprature or else.
This message shoud go to the output i whant.
Summary
var buffer = msg.payload;
msg = [];
for (var i = 0; i < buffer.length; i++) {
if (buffer[i] == 0x0d); //boiler
{
i++;
msg [0] = {payload : buffer.readUInt16BE(8)/10};
continue;//next loop
}
if (buffer[i] == 0x0f); //Abgas
{
i++;
msg [1] = { payload: buffer.readUInt16BE(i) / 10 };
continue;//next loop
}
//if (buf = ....); //Kessel ........
//{...}
if (buffer[i] == 0x7d);
{
msg [12] = { payload: "Timestamp" }
}
if (buffer[i] != 0x7d);
{
continue;
}
//else; //anything else
//{
//continue;}
}
node.warn ()
return msg;
Debug logs only 1 Value, but he can find more.
My inject Buffer was with all request i would do (not the answer of the heater).
I dont think this is the best way to handel it, but once of them i tried you can see a part in the background.
In this case i think it can`t be or I cant select the byte witch is to read out of the array with [ i ], and if i try "else"in the loop i got error.
If anyone think this is the wrong way, or even think i shoud try/do something else please tell me.