Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chirpstack V3->V4 decoder compatibility #58

Open
kgarwoodsdzwa opened this issue Aug 31, 2023 · 0 comments
Open

Chirpstack V3->V4 decoder compatibility #58

kgarwoodsdzwa opened this issue Aug 31, 2023 · 0 comments

Comments

@kgarwoodsdzwa
Copy link

I used this code but with Chirpstack as my server instead of TTN so it's not an issue per-se, but just in case anyone else does the same thing. It gave me a decoder error when I checked the device log, and I found that Chirpstack V4 needs the decoder in a bit of a different format. When I used the format below it worked perfectly!
`function decodeUplink(input) {
return {
data: Decoder(input.bytes, input.fPort)
};
}

function Decoder(bytes) {
var decoded = {};

decoded.latitude = ((bytes[0] << 16) >>> 0) + ((bytes[1] << 8) >>> 0) + bytes[2];
decoded.latitude = (decoded.latitude / 16777215.0 * 180) - 90;

decoded.longitude = ((bytes[3] << 16) >>> 0) + ((bytes[4] << 8) >>> 0) + bytes[5];
decoded.longitude = (decoded.longitude / 16777215.0 * 360) - 180;

var altValue = ((bytes[6] << 8) >>> 0) + bytes[7];
var sign = bytes[6] & (1 << 7);
if (sign) decoded.altitude = 0xFFFF0000 | altValue;
else decoded.altitude = altValue;

decoded.hdop = bytes[8] / 10.0;
decoded.sats = bytes[9];

return decoded;

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant