LoRaWAN-Signal-Mapping/server/ttn-app-server/DecodePayload.mjs

20 lines
547 B
JavaScript

"use strict";
const offset_id = 0;
const offset_lat = 32 / 8;
const offset_lng = (32 / 8) + (32 / 8);
function decode_payload(payload_base64) {
let payload_buffer = Buffer.from(payload_base64, "base64");
// console.debug(`Offsets: ${offset_id}, ${offset_lat}, ${offset_lng}`);
// console.debug(`Message hex: ${payload_buffer.toString("hex")}`)
return {
id: payload_buffer.readUInt32LE(offset_id),
latitude: payload_buffer.readFloatLE(offset_lat),
longitude: payload_buffer.readFloatLE(offset_lng)
};
}
export { decode_payload };