From 94cd5a8743e1ff2658d0d609ca37b9cc37976607 Mon Sep 17 00:00:00 2001 From: cheetah Date: Mon, 29 Mar 2021 16:14:04 +0200 Subject: [PATCH] Create gpsonly.js --- birdy-slim-iot/payload-formatters/gpsonly.js | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 birdy-slim-iot/payload-formatters/gpsonly.js diff --git a/birdy-slim-iot/payload-formatters/gpsonly.js b/birdy-slim-iot/payload-formatters/gpsonly.js new file mode 100644 index 0000000..cb1e0e1 --- /dev/null +++ b/birdy-slim-iot/payload-formatters/gpsonly.js @@ -0,0 +1,25 @@ +// TTN V2 +function Decoder(bytes, port) { + var decoded = {}; + decoded.latitude = ((bytes[0]<<24)>>>0) + ((bytes[1]<<16)>>>0) + ((bytes[2]<<8)>>>0) + bytes[3]; + decoded.latitude /= 10e4; + decoded.longitude = ((bytes[4]<<24)>>>0) + ((bytes[5]<<16)>>>0) + ((bytes[6]<<8)>>>0) + bytes[7]; + decoded.longitude /= 10e4; + decoded.dur = bytes[8]; + return decoded; +} + +// TTN V3 +function decodeUplink(input) { + const bytes = input.bytes, data = {} + data.latitude = ((bytes[0]<<24)>>>0) + ((bytes[1]<<16)>>>0) + ((bytes[2]<<8)>>>0) + bytes[3]; + data.latitude /= 10e4; + data.longitude = ((bytes[4]<<24)>>>0) + ((bytes[5]<<16)>>>0) + ((bytes[6]<<8)>>>0) + bytes[7]; + data.longitude /= 10e4; + data.dur = bytes[8]; + return { + data, + warnings: [], + errors: [] + }; +}