Private Location Tracking/Sharing

Written 7 years ago by Mike Cardwell

For a while now, on and off, I’ve been looking for a way to live track my location and hook it into my home automation setup. This is a difficult task to achieve when you care about your privacy. I am not interested in giving another third party a history of my movements; it’s bad enough that my cell provider gets this information due to my need to connect to cell towers. I don’t care if your privacy policy tells me you wont share my information and your CEO tells me you “take security very seriously”. That wont help me when you get hacked or decide to change your privacy policy.

Anyway, I’ve finally found a solution which fits my needs perfectly. In fact, it comfortably exceeds my requirements by virtue of being open source. The application I’m talking about is OwnTracks (source). It comes in both Android and iOS flavours, and it allows you (in fact, encourages you) to use your own server.

The server can be either a HTTP service, or preferably an MQTT service. Despite my initial desire to go the HTTP route, I heeded the advice in the OwnTracks documentation and looked into MQTT (not being something I’d heard of before), and I’m glad I did. With a quick “apt-get install mosquitto mosquitto-clients” and a few minutes of reading documentation, I had an MQTT server installed and configured.

I believe the behaviour is different for iOS devices, but on Android devices at least, OwnTracks connects to your MQTT server, and publishes location updates as blobs of JSON. You can connect up other MQTT clients to that server and listen out for those events. I use the excellent NodeJS “mqtt“ package to do exactly this. You can also configure authentication and ACLs to control which users have access to which locations, meaning that you can optionally share location data with other friends who connect to your MQTT server. The OwnTracks app displays the locations of everyone you can see, on a map. And if your friends don’t want to connect to your MQTT server? They can connect to their own, and you can bridge them together!

Battery life? OwnTracks seems to work hard to not work hard. OwnTracks asks your device to notify it only when it’s in motion, or when you’ve entered or left a user defined waypoint. When you’re in motion, it will publish location updates to the server according to user defined time periods and distances travelled.

There was one issue with the above algorithm. If your phone is stationary for a long period of time, you don’t get updates (I believe the iOS version can be set to send on an interval). So when your last published location was 12 hours ago, you don’t know if you haven’t received any updates because you haven’t moved, or because your phone ran out of battery/network access. To deal with this, I enabled “Remote commands” in the OwnTracks interface, and set up a job on my server to run the following command every 30 minutes:

mosquitto_pub -u YourUsername -P YourPassword -t 'owntracks/mike/phone/cmd' -m '{"_type":"cmd","action":"reportLocation"}'

OwnTracks not only publishes to the MQTT server, but it subscribes to “topics” on it too, so when it sees a “reportLocation” request. It knows that it should immediately report it’s location. This means I get updates at least every half an hour regardless of whether or not I’ve moved.

And if there is no network access? OwnTracks batches up the location changes and publishes them once network access is available again.

Don’t have a static IP to stick an MQTT server on? You have a permanently running machine, but it’s behind a weird NAT setup that you can’t get around? If you have an Android phone, fear not, you can run your MQTT server behind a Tor Hidden Service, install Orbot on your device, configure Orbot to force all traffic from OwnTracks through Tor, and configure OwnTracks to talk to your hidden service hostname. How do I know that this works? Because that’s exactly what I’m doing. This has the added benefit that anybody monitoring your servers network (your ISP or hosting provider), wont be able to track your movements from IP to IP due to your regular MQTT traffic.

And to top it all, the documentation is excellent: detailed, but not dumbed down; and the developers are quick to respond to issues on Github.

Wiring the IoT MQTT Essentials - A Lightweight IoT Protocol

Want to leave a tip?BitcoinMoneroZcashPaypalYou can follow this Blog using RSS. To read more, visit my blog index.