Dude, where is my car? (Geofencing) - Part 3
In 2018 I started a project to be able to track my car in real time. Additionally, my idea was to use it as a car alarm system. I went through different iterations until I had a working system with which I was satisfied. This is the third part of a blog post series that describes how to track your car in real time and how to use it as a car alarm system.
The Current State of Affairs
I am now able to track my car in real-time and since I use an end-to-end encrypted GPS tracking service (ChasR), I am still able to protect my privacy. However, my goal was to build a car alarm system. At the moment, I need a hint or gut feeling that my car was stolen so I would check its location. This is obviously not a good alarm system. I have to build something that monitors the location of my car and then alerts me if something is off.
The Idea: Geofencing
The question is: how do I detect that my car is moved by someone that is not supposed to move it? Well, my first idea was to make an on/off switch for the car alarm system. However, I am pretty sure I would forget switching it on or off quite often (or my wife would) and thus would get a lot of false-positive alert messages which would in time lead to alarm fatigue.
My next thought was that my car usually drives around only in my town and the neighboring towns. A thief stealing my car would certainly not staying in town. How about monitoring if the car moves outside of these usual areas? Well, obviously I am not the first one who thought about it. This technique is called geofencing and I thought it is worth pursuing.
Here is an example to make it more visual (I used the following website to create the image). Let us say I live in Berlin and usually only drive around in center, west and south Berlin. Then I could use the following two geofences to determine that my car was stolen or not. If the car resides inside the geofences, everything is fine. If it goes outside, I get a notification.

However, since I use an end-to-end encrypted GPS tracking system, I am not able to integrate the monitoring mechanism into the GPS tracking system itself (no, I will not go down the rabbit hole called "homomorphic encryption"). Hence, the only viable solution is to have a small service running at home that periodically fetches the current location of my car from the GPS tracking service and then processes it. If my car is outside the geofence, this service has to notify me about it and then I can check and react accordingly.
The Implementation
For this to work, I needed to implement a small service that fetches the GPS data, processes it and sends me a notification. Sounds easy enough. However, I am lazy and do not want to build everything from ground up myself (yes, even if I built the whole end-to-end encrypted GPS tracking system because nothing like this existed). So I thought I could integrate this service into an existing monitoring system. I settled to integrate it into AlertR, because it has a modular build and already offers me notification capabilities (ok, this is quite a bad example of "I am lazy and do not want to do everything myself" because I am also the author of AlertR :/ ). I also added a tutorial to the AlertR wiki to set up the monitoring service. After I installed everything needed for the monitoring service on an old Raspberry Pi 2, every time my car leaves the geofence I get a push notification on my phone:

Furthermore, choosing AlertR gives me additional interesting possibilities. I could also use the geofencing for some kind of home automation. For example, I could check if the car gets parked in front of my house and then turn on the thermostats in winter.
- Part 1: Choosing the GPS tracking system and tracking my car with a Raspberry Pi
- Part 2: Using an old Android mobile phone to track my car
- Part 3: Building a car alarm system using geofencing (this article)
The Current State of Affairs
I am now able to track my car in real-time and since I use an end-to-end encrypted GPS tracking service (ChasR), I am still able to protect my privacy. However, my goal was to build a car alarm system. At the moment, I need a hint or gut feeling that my car was stolen so I would check its location. This is obviously not a good alarm system. I have to build something that monitors the location of my car and then alerts me if something is off.
The Idea: Geofencing
The question is: how do I detect that my car is moved by someone that is not supposed to move it? Well, my first idea was to make an on/off switch for the car alarm system. However, I am pretty sure I would forget switching it on or off quite often (or my wife would) and thus would get a lot of false-positive alert messages which would in time lead to alarm fatigue.
My next thought was that my car usually drives around only in my town and the neighboring towns. A thief stealing my car would certainly not staying in town. How about monitoring if the car moves outside of these usual areas? Well, obviously I am not the first one who thought about it. This technique is called geofencing and I thought it is worth pursuing.
Here is an example to make it more visual (I used the following website to create the image). Let us say I live in Berlin and usually only drive around in center, west and south Berlin. Then I could use the following two geofences to determine that my car was stolen or not. If the car resides inside the geofences, everything is fine. If it goes outside, I get a notification.

However, since I use an end-to-end encrypted GPS tracking system, I am not able to integrate the monitoring mechanism into the GPS tracking system itself (no, I will not go down the rabbit hole called "homomorphic encryption"). Hence, the only viable solution is to have a small service running at home that periodically fetches the current location of my car from the GPS tracking service and then processes it. If my car is outside the geofence, this service has to notify me about it and then I can check and react accordingly.
The Implementation
For this to work, I needed to implement a small service that fetches the GPS data, processes it and sends me a notification. Sounds easy enough. However, I am lazy and do not want to build everything from ground up myself (yes, even if I built the whole end-to-end encrypted GPS tracking system because nothing like this existed). So I thought I could integrate this service into an existing monitoring system. I settled to integrate it into AlertR, because it has a modular build and already offers me notification capabilities (ok, this is quite a bad example of "I am lazy and do not want to do everything myself" because I am also the author of AlertR :/ ). I also added a tutorial to the AlertR wiki to set up the monitoring service. After I installed everything needed for the monitoring service on an old Raspberry Pi 2, every time my car leaves the geofence I get a push notification on my phone:

Furthermore, choosing AlertR gives me additional interesting possibilities. I could also use the geofencing for some kind of home automation. For example, I could check if the car gets parked in front of my house and then turn on the thermostats in winter.