Help with payload codec


I have set up the full LoraServer OS on a Lorix One with postgres integration.

We got some quite neat pulse counter devices from Vega Absolute. Their payload description is as per the screenshot below.

I’m struggling with the unfamiliar javascript needed to decode the payload.

So far, I get some of the values we need, but crucially it will not decode the timestamp of the readings sent.

The javascript I am using is:

// SI-11: Payload Decoder
function Decode(fPort, bytes) {
var decoded = {};

    // Packet Type
    //decoded.packettype = bytes[0];

    // BATTERY
    decoded.battery = bytes[1];

    // Basic Settings
    //decoded.basic_settings = bytes[2];

    // ReadingTime
    decoded.readingtime = bytes.slice(3,6);

    // Temperature
    decoded.temperature = bytes[7];

    // Pulse 1
    decoded.reading1 = parseInt(bytes.slice(8, 11));

    // Pulse 2
    decoded.reading2 = parseInt(bytes.slice(12, 15));

    // Pulse 3
    decoded.reading3 = parseInt(bytes.slice(16, 19));

    // Pulse 4
    decoded.reading4 = parseInt(bytes.slice(20, 23));

return decoded;


What I am getting in the database is:

{“battery”: 99, “reading1”: 72, “reading2”: 0, “reading3”: 0, “reading4”: 4, “readingtime”: “ABp5”, “temperature”: 25}

As you can see the timestamp (readingtime) is a problem. It should be unix time so I am expecting the results to be a number such as 1568275686. What I am getting appears to be base64? And that does not decode into anything that makes sense.

I think the problem relates somehow to the way my javascript “slices” bytes from the payload string (excuse my ignorance if what I am saying makes no sense).

The reason I think that is, for example if I take the result returned for the timestamp in the above example (ABp5) and decode it, its seems that is only three bytes (see attached screenshot), not 4 bytes as per the payload documentation. I have checked the pulse reading fields (which should also be 4 bytes) and it seems that in those case I am also only getting three bytes.

So I suspect my javascript is faulty. But as far as I can tell I have selected the correct bytes from the string.

If anyone can see the problem please help me out.

// if uint32 (lsb/msb protocol could not see. Try the reverse order.)
decoded.readingtime = ( bytes[3] << 24 ) + ( bytes[4] << 16 ) + ( bytes[5] << 8 ) + bytes[6]

Thanks a million!

That helped me solve the issue.

1 Like