Geofence IDs not working

Usman Khana year ago

Alright , So I am doing in such a way that when the user draw a geofence on the map it detects the devices under that drawn fence which are not connected to any fence then we need to connect all those device to that geofence. It can be 1 - 1000 or more devices ,

But I got what you said and I'll research on that.

Thanks for your time :)

Usman Khana year ago

HI Anton Tananaev!

So, I am sorry for bothering you again with the same issue.
So clearly mention that if we have to manually attache a device with a fence which Api we need, as far I have studied we need a linker Api that will link between the device and geofence:

{{baseUrl}}/permissions
Body : {"deviceId": 8, "geofenceId": 376}

the response is 204 here ,

I fetch the device 8 and here it is

{{baseUrl}}/devices?id=8

The response :

    {
        "id": 8,
        "attributes": {},
        "groupId": 0,
        "name": "RF-V34/1403152554",
        "uniqueId": "1403152554",
        "status": "offline",
        "lastUpdate": "2023-01-11T10:44:07.806+00:00",
        "positionId": 27886,
        "geofenceIds": null,
        "phone": "2365",
        "model": "RF-V34",
        "contact": null,
        "category": "tracker",
        "disabled": false,
        "expirationTime": null
    }

why its not updating when I will do like this using postman.

Please guide me if I am doing anything wrong or can you tell me how to do this task.

Anton Tananaeva year ago

Because you're looking in the wrong place. The field in the devices model is not for all linked geofences, but only the ones that the device is currently in.

Usman Khana year ago

Thanks for the Response Anton Tananaev,

So the device will update its Geofenceid via linker api only if the device is within the fence ?

Anton Tananaeva year ago

The API does not update that field.

Usman Khana year ago

How is the field updated then?

Anton Tananaeva year ago

Automatically once the geofence is linked.

Usman Khana year ago

OK Got it thanks for the Replies Anton, Have a nice weekend :)

Usman Khana year ago

HI Anton Tananaev,

I am sorry I am bothering you again and again ,

  • So the devices are online and with in the fence
  • I am calling the Permission API call for the device to attached them with the fence.
  • what can be the reason the device is not getting connected with the fence even if the Permission Api respond is 204.

My logic works on the basis of the GeofenceIDs attribute in the device object that traccar update by itself after permission API is called.

can you please help me here
Thank you .

Best Regards,
Usman Khan

Anton Tananaeva year ago

How are you checking if they are connected or not?

Usman Khana year ago

I see if the Device object in the redux get Updated with the geofenceIds

Usman Khana year ago

And also fetch the device in the postman but I do not see any Geofenceids

Anton Tananaeva year ago

As I said previously, it's NOT the right place to check.

Usman Khana year ago

Then How should I know if the device is connected or not?

Sometimes it works as I call the permission Api and the Redux is updated
But sometime it does not work

Anton Tananaeva year ago

You can call something like this:

GET /api/geofences?deviceId=X

This will return all linked geofences, assuming the user has access to them too.