Project

General

Profile

Trying to decode RF12 binary packages with NodeRed JavaScript

Added by cpfeil81 2 months 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


Replies (1)

RE: Trying to decode RF12 binary packages with NodeRed JavaScript - Added by JohnO about 2 months ago

Hi Christian,

Its been a while, sorry we seem to have missed your message. Did you get to a solution?
When receiving a pair of 8 bit values representing a 16 bit value the lowest 8 bits are received first and then the high order eight bits are received as the second byte. Same approach for 32 bit numbers, lowest order byte is received first and highest order byte comes last.

    (1-1/1)