What do you mean by "does not distinguish which device sent the position"? Each position has the device id, so you know what device sent it.
Ok I mean that I don't have an api can fetch last position for specific device
Example 127.0.0.1:8082/api/socket/{device_id}
You can always filter the WebSocket data by the id. There's no other alternatives currently.
That mean this api exist ?
127.0.0.1:8082/api/socket/{device_id}
No, it doesn't. I'm talking about filtering on your end.
ok thank you.
I mentioned earlier that I have a problem with the socket api because the api cannot fetch data without i connect on traccar web interface
Is there a way to solve this؟
If you can't, you're doing something wrong. It's an API, so you should be able to use it directly.
track_devices:590
WebSocket connection to 'ws://127.0.0.1:8082/api/socket' failed:
there is my implementation
let socket = new WebSocket("ws://127.0.0.1:8082/api/socket");
var map;
map = L.map('map',{editable: true}).setView([18.0928, -15.9611], 13);
var gmaps=L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
});
gmaps.addTo(map);
// console.log(socket.url)
let feature = null;
socket.onmessage = function(msg) {
console.log(msg.data);
let data = JSON.parse(msg.data);
if (data.hasOwnProperty('positions')) {
let position = data.positions[0];
if (feature === null) {
feature = L.marker([position.longitude, position.latitude]);
feature.addTo(map);
} else {
var newLatLng = new L.LatLng(position.longitude, position.latitude);
feature.setLatLng(newLatLng);
}
}
};
The exact problem that I mentioned is that I am unable to fetch from the socket API unless I am also connected to the Traccar interface at the same time. If I connect, the error disappears.
How to configure Traccar to send events to my Django application using Traccar webhooks or any other suitable option?
I have developed a Django application based on the Traccar server database, and now I want to listen for changes in the positions table. The Traccar server automatically populates the positions table with coordinates sent by the device. Although there is an API socket offered by Traccar that can fetch positions, I am looking for something better than the API because it only gives the last position sent by devices and does not distinguish which device sent the position. Do you have any ideas about this?
I have too a problem with the api because I cannot fetch from api without connecting on traccar web interface