TTN Integration - Watch variable with Location on Map

Hi, I have created a TagoIO application integrated with TTN. At TagoIO, I need to show 2 variables on a map, so I must send a location (with latitude and longitude) field on JSON object, as Tago requires. I have tried to add the location variable on the decoder function, but the TagoIO payload parser always separate this information on a different JSON object. I’ll explain better.

On TagoIO Help Center, it says: “To display locations on a Map, your data needs to be sent inside the “location” field with the format shown below:”

{
  "variable": "speed",
  "value": 10,
  "location": {
    "lat": 42.2974279,
    "lng": -85.628292
  }
}

So I have tried the following Decoder Functions:

function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.

  var decoded = {};
  var FillLevel = bytes[0];
  var BatteryLevel = (bytes[1] << 8) + bytes[2];  
  return{
    "myvariable1" : {
      "variable": "FillLevel",
      "value": FillLevel,
      "location":{
         "lat": -22.006680,
         "lng": -47.896187
         }
    },
      
      
      "myvariable2" : {
        "variable": "BatteryLevel",
        "value": BatteryLevel/100,
        "location":{
         "lat": -22.006680,
         "lng": -47.896187
        }
      }
      

  };
}

and a more simple one,

function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.

  var decoded = {};
  var FillLevel = bytes[0];
  var BatteryLevel = (bytes[1] << 8) + bytes[2];  
  return{
    "FillLevel": FillLevel,
    "BatteryLevel": BatteryLevel/100,
    "location": {
      "lat": -22.00668,
      "lng": -47.896187
    }
  };
}

None of them worked (I have also tried other variations of decoder functions, with no success). When using the Live Inspector on Tago, I always see something like that:

In some situations, TagoIO creates a variable called “location_location”, with the location field required. But the “value” field is always equal to the “latitude” variable, so I can only see this on dashboard map, not the “BatteryLevel” or “FillLevel” variable value I need.

That means I’m either sending the data on a wrong format on TTN, or parsing the data wrongly on TagoIO (I couldn’t understand the parsing function correctly).
Have anyone ever tried to do something related to this? I’m desperate. I’m also posting this on TTN community center.

Thanks!

Hi Henrique,
A few tips first:

  1. With Map you only need one of the variables to have the location parameter. You can change the Group By to Serie and you’ll see the variables being grouped in one only infobox.

  2. TagoIO fixed the problem where you could only see the latitude on location value from TTN.

  3. I don’t know where you did get these codes. Have you tried to see the TagoIO Snippets for payload parsers and the documentation? You can write a very simple code for what you need:

const location_var = payload.find(x => x.variable === ‘location’`);
const batterylevel_var = payload.find (x => x.variable.toLowerCase() === ‘batterylevel’)
// I can see your payload already send the batterylevel and the location
// so we find these variables in the payload and edit them.

if (location_var && batterylevel_var) {
// copy the location parameter to batterylevel variable.
batterylevel_var.location = location_var.location;
}