Thanks but according to this post ( Incorrect longitude latitude in KPN dashboard ) latitude is supposed to be found in bytes 6-9 (zero indexed) for my device’s TTN payload (ONE V3). Are you using TTN and ONE V3?
What’s confusing is that the Lat/Lon output from my script are quite close to correct … just not what they should be.
Your payload must be formatted differently - can the type of gateway affect that?
If I take my payload string and manual copy bytes 6-9 (lat) and 10-13 (lon) and then paste each into https://www.rapidtables.com/convert/number/hex-to-decimal.html
the “Decimal from signed 2’s complement:” result shows the precise location of my tracker as verified by Google Earth.
I shouldn’t think the gateway makes any difference, but the sketch file loaded in your device certainly does. As I understand it, there are at least two versions floating around. One written specifically for the One V3 and a ‘universal’ one that works on multiple devices. I was not able to get the universal one to work correctly.
OK, I found the error, which was in my code for the mapping application and not the TTN payload Decoder. Sorry for this series of posts.
The following are correct for the version of Universal Tracker I am using:
var long = (bytes[13] << 24) | (bytes[12] << 16) | (bytes[11] << 8) | bytes[10];
var lat = (bytes[9] << 24) | (bytes[8] << 16) | (bytes[7] << 8) | bytes[6];
sorry for asking, first of all I didnt know much about json. I tried to use your code, unfortunately I received this Error(“json: unsupported value: NaN”). In any case do you how to solve this?
Sorry - I was in the same position WRT json coding expertise. As I recall, I just searched for decoder examples and played around until I found something that worked.