[help] Traccar api: determine if device is online or offline

brenthmiras8 years ago

Is there a way to monitor device status whether online or online via api? Something like a hook, or an event emitter or a web socket? I need to build an app that shows the devices and show if they are online just like the web interface.

abyss8 years ago

Yes, device object is sent to websocket if status is changed.

brenthmiras8 years ago

Can you please give me a link to the web socket documentation? What messages are sent and accepted by the web socket server. I am able to access the wss @ wss://<myip>/api/socket
I just don't know how to catch events, specifically when device turns online or offline.

brenthmiras8 years ago

Upon connection to web socket, the server sends a message containing device positions. But it seems there is no data on whether the devices are online or offline. Here is a response: http://pastebin.com/hYWqNMbe

abyss8 years ago

I'm afraid there is now documentation for websocket at the moment.

You can study code of official web-client. This functions response for handling websocket messages from server: https://github.com/tananaev/traccar-web/blob/master/web/app/controller/Root.js#L122

Initial device state you can get via GET api/devices

If device status changes it will be sent to websocket.

brenthmiras8 years ago

Thank you very much!!!

Nick6 years ago

Hello @brenthmiras, @abyss and Anton,

I'm able to access the websocket directly without any authentication. The documentation also mentions that there is only 'session cookie' as authorization option.

I'm able to access the websocket using ws://<myServer>/gps/api/socket using firefox or chrome addons, so is there any way of security that I can deter others from accessing my webserver socket and accessing my devices' information and events? Or perhaps add some security on the server side to make it just available to me?

Anton Tananaev6 years ago

It's not possible to access it without authentication. Most likely you can access it because you are already logged in on the same browser.