Project

General

Profile

Trying to decode RF12 binary packages with NodeRed JavaScript

Added by cpfeil81 12 days ago

Hi,

I hope anyone can help me please!

I am trying to decode RFM12B binary packets I receive with my Jeelink.

Examples:

OK 45 0 0 164 12
OK 43 0 11 72 3 0 0
OK 52 205 0 20 0 133 8 195 11

Here is my code.

msg.payload contains the input from the jeelink (see above).
The ID is decoded correct, but the data seems to be decoded wrong.


if (msg.payload.lastIndexOf('OK') == 1) 
{
    var completeMSG = msg.payload;

    var tokens = new Array();
    tokens = msg.payload.split(" ");

    tokens.shift();

    var nodeid = tokens.shift() & 0x1F;

    var b1 = tokens.shift();
    var b2 = tokens.shift();
    var b3 = tokens.shift();
    var b4 = tokens.shift();
    var b5 = tokens.shift();
    var b6 = tokens.shift();


    var val1 = b1 + 256 * b2;
    var val2 = b3 + 256 * b4;
    var val3 = b5 + 256 * b6;
    return completeMSG;
    //return nodeid + " - " + val1 + " - " + val2 + " - " + val3;
}
else
    return "";

Best regards,

Christian