few months ago, I was thinking about having my car tracked over GPS to make sure it is where I left it and to have some records how much I drive etc. There are commercial systems available for this but they cost some money and I wanted to have it customizable, under own control and to implement a few own ideas so I designed and implemented the system by myself. This is how CarWatch was born.
First you need to have some kind of device with GPS receiver and network connection. Other people build it from Arduino, GPS modules, GSM modules, accelerometers and glue it with firmware. This setup is quite complicated to build and even more complicated to debug or upgrade. I also wanted other people to be able to build it themselves without complicated soldering or programming so I came up with an idea that I won’t be messing with any hardware construction and I’ll use old Android phone which has all these features. Everyone has some old Android phone lying in his electronic trash so why not to give it a new life. All you might need to buy is 12V to 5V micro USB converter. I recommend these:
Hardware was easy job but the main part was writing software. I needed to write both server and client side of my application.
I’ve had some experience with coding for Android (although I’m not any professional coder) and wanted it to be super simple from user point of view, so there are not any customizable settings in this app. Download, install, register and activate. Then hide the phone somewhere in your car. That’s all.
This app runs as service and starts right after phone boot. It regularly (each few seconds) sends new data to CarWatch tower (server) as simple UDP packet. I wanted to avoid any statefull connection so in case of interrupted connectivity some packets just don’t arrive to tower and the connection continues right after. I also wanted the data to be cryptographically authenticated so I sign them with SHA-256 hash which is salted with string generated at registration.
As a server, I’m using python script which only listens on UDP and saves all incoming packets to database. Then there is a separate script which processes new packets, validates them against stored salt and processes data.
Each data record is saved in following table:
CREATE TABLE `data` ( `id` int(11) NOT NULL, `subject_id` int(11) NOT NULL, `timestamp` datetime NOT NULL DEFAULT '2000-01-01 00:00:00', `ip` varchar(255) NOT NULL, `port` int(4) NOT NULL, `verified` tinyint(4) NOT NULL, `local_time` bigint(20) NOT NULL, `GPSLon` double NOT NULL, `GPSLat` double NOT NULL, `GPSSpd` float NOT NULL, `GPSAcc` double NOT NULL, `GPSTimestamp` bigint(20) NOT NULL, `GPSSeen` tinyint(4) NOT NULL, `GPSUsed` tinyint(4) NOT NULL, `NETLon` double NOT NULL, `NETLat` double NOT NULL, `NETAcc` double NOT NULL, `NETTimestamp` bigint(20) NOT NULL, `ACC_X` double NOT NULL, `ACC_Y` double NOT NULL, `ACC_Z` double NOT NULL, `BATPercent` tinyint(4) NOT NULL, `BATCharging` tinyint(4) NOT NULL, `BATTemp` float NOT NULL, UNIQUE KEY `id` (`id`), KEY `timestamp` (`timestamp`), KEY `subject_id` (`subject_id`), KEY `GPSSpd` (`GPSSpd`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
This script also assigns zero or more of these states to each car after packet processing:
- NEW – car just created, no data so far
- DATA_MISSING – no packet received from car for defined time
- GPS_LOST – data received but GPS timestamp too old
- GPS_MOVE – GPSSpd > 0
- NOT_CHARGING – phone disconnected from charger
- BAT_OVERHEAT – battery temperature higher than threshold
- DATA_UNSECURE – data came with invalid signature
Every time the state changes, you can get an e-mail with latest data about car and map with its latest position.
I also built a simple web portal, where I can see current car position and also its history. It’s built on top of UserFrosting platform to save some development time. This is where you need to register before installing app to phone. You can see drive maps, current car state and position, historical stats and all your registered cars here. Some screenshots here:
- GPS position
- GSM/3G network position (buggy)
- accelerometer monitoring (strange)
- battery status (temp, charge)
- e-mail notifications
- cryptographic authentication
- event logging (on each status change)
- speed & temp grapphing
- time seek bar with speed display
- traveled distance measurement
- real-time car following
- call autoanswer (you can listen what happens in car)
- remote commands from server (upgrade (with rooted device only), setInterval)
If you want to try it, go ahead, register and try it! I’ll be glad. I also welcome any feedback concerning the idea or implemented features.
This is the question I am facing now. What to do with this whole project? It already has some neat features implemented, some of them are not so well done but generally it works to my satisfaction. I have some more ideas what could be done (OBDII logging, owner sensing via BT, SMS callback, etc.) but they would take time and I’m not sure if it’s worth it if it’s going to be used only by myself. That’s also the main reason I’m writing this post.
What would you recommend me to do? Would you like to use such product? Do you think it’s worth it? Let me know in comments please.
Thank you for reading. Looking forward to your comments!