Ubidots Community

Ubidots geofence event not working

Hello,
I am working on a project and this is the first time using Ubidots and IoT devices. I am trying to put a geofence in, and it seems like I just need to have my output be in this format -
{“position”: {“value”:1, “context”:{“lat”:25.7742700, “lng”: -80.1936600}}}
but I’m struggling with how to do that. My decoder is:

function Decoder(bytes, port)
{
var longitude_int, latitude_int;
var decoded = {};

if (port === 2) {
if(bytes[0]==9) // check if the header byte is 9.
{
latitude_int = (bytes[1] << 24) | (bytes[2] << 16) | (bytes[3] << 8) | (bytes[4]);
decoded.latitude = latitude_int / 100000;
longitude_int = (bytes[6] << 24) | (bytes[7] << 16) | (bytes[8] << 8) | (bytes[9]);
decoded.longitude = longitude_int / 100000;
return decoded;
}
}
}

But at the same time, my map widget updates, so I would think the event would work too. What else can I check if the format isn’t the issue?

Hello, cseby2000

I hope this note finds you well,

In order to create an object that holds the data in the format needed for the geo fence to work keep in mind that in JavaScript you can built it like this, for instance:

let latitude = 25.7742700;
let longitude = -80.1936600;
let payload = {"position":{"value":1, "context":{"lat":latitude, "lng":longitude}}};
console.log(payload);

I hope this may help you to build the payload in the format required.

Regards,

-Santiago

Thank you for confirming this. I was able to get it to the correct format and it is working.

you’re welcome.