Universal Tracker Longitude error - decoder problem

I’m running SodaqOne-UniversalTracker-v3 on the Cattle Tracker and sending data to TTN. I’m using a payload decoder based on the decoder examples here for TTN: Interpreting payload data from the SodaqOne-UniversalTracker

However, the Longitude value returned is consistently off by 1.5Km east. Other values (Latitude, altitude) seem reasonable.

I manually converted the payload to Lon/Lat so something wrong with the Javascript code for decoding longitude but I don’t see what it is:

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];

Any ideas on how to fix this? Thanks

This is the decoder I’m using. It seems to work fine:

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

decode.batt = ((bytes[13] << 8 | bytes[14])/100) / 4.2 * 100;
decode.temp = ((bytes[17] << 8 | bytes[18])/10) * 9/5 +32;
decode.lat = (bytes[4] + (bytes[3]<<8) + (bytes[2]<<16) + (bytes[2] & 0x80 ? 0xFF<<24 : 0)) / 10000;
decode.lon = (bytes[7] + (bytes[6]<<8) + (bytes[5]<<16) + (bytes[5] & 0x80 ? 0xFF<<24 : 0)) / 10000;
decode.alt = (bytes[9] << 8 | bytes[10])/100 * 3.28084;
decode.all = [decode.lat, decode.lon, decode.alt, decode.batt, decode.temp];
return decode;
}

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.

Yes, I have a One v3 and am connected through TTN.

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];

I’m using this version:

Hi @wrldtvlr,

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?

regards,

Aishah

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.

1 Like