Please consider leaving a donation if you appreciate this information. Lightning network now available
My wife and I are currently on an overland trip down the Pan-American Highway. You can read more about that on The Life Nomadic. As we were making preparations for that trip we did what most people would do in a similar situation, we started reading blogs about this kind of trip. No reason to make all the mistakes ourselves, right? As we were in the early stages of planning, I was quite focused on the vehicle itself and read several lists of modifications than people had done. On a few of those lists there was some mention of adding a secret toggle switch to prevent the vehicle from being hot-wired. Not terrible advice by any means, but the fact is, vehicles aren’t really stolen that way anymore (are they?).
Over-complicating things is one of my favorite things to do and over-complicating something as simple as a toggle switch? How does one even do that…read on.
The Basic Idea
The idea itself was relatively simple. Create a two-part system and if the two parts become separated, do something (like cut the fuel). This is a pretty common safety feature on jet-skis and snowmobiles. Our truck isn’t a snowmobile and I’m not terribly concerned with falling off. I’m more concerned that some na’er-do-well would stick a gun through the window and take the vehicle by force (I’m pretty sure that this is how vehicles are stolen these days). The last thing I want to do in that type of situation is to prevent said na’er-do-well from making a hasty getaway I’d just as soon put a bit of distance between them and us. A physical tether such as the jet-ski/snowmobile safety device just isn’t pratical for this, but a Bluetooth beacon is.
Bluetooth low energy (BTLE) systems are becoming more and more popular. One common use-case is in retail. If a shopper with a bluetooth device such as a smartphone comes into close proximity of an item the beacon, in combination with an app running on the smartphone, that shopper can be prompted and perhaps enticed to take action such as purchasing the item. **BOOM** there’s my solution 🙂 The two parts of my security system would be a Raspberry Pi and a BTLE beacon.
Challenge 1
The first challenge to overcome was how to make that work. Pi enthusiasts will probably hate me for not creating a Python software solution but I’ve never really bothered to learn anything Python. Instead, I opted for a node.js solution only because I’m somewhat familiar with node and people way smarter than me have already done most of the work. The modules that I ended up using are Bleacon and wiringPi. Bleacon allows for scanning and detecting BTLE devices and wiringPi allows for changing the state of the Pi’s GPIO pins. Standard JavaScript methods setTimeout and setInterval would prove very capable of performing the tasks I needed to perform.
Challenge 2
The next interesting challenge was how to prevent Pi from draining the vehicle battery. A flat battery will do a lot to prevent a vehicle from being stolen but also renders a vehicle pretty much useless. Without taking any measurments of current draw of the Pi or even simply googling, I just assumed that buying a massive backup battery would do the trick. Sadly, I was mistaken. The battery that I bought could only power Pi for ~36 hours in my testing. It also didn’t really provide any easy way to cycle the power to boot Pi. After several attempts to remedy that bit (attempts involving drill bits and solder irons) I gave up on that notion and opted for a standard Bosch style autmotive relay to cycle power to the Pi when the ignition circuit was energized. This resulted in sub-challenge 1: What happens if the vehicle doesn’t actually start when the ignition circuit is energized and sub-challenge 2: What about stopping for fuel and the key is cycled off? All of these challenges were eventually solved, I’ll get back to them later.
The Final Outcome
My security system consists of the following hardware:
- Raspberry Pi 3
- Sainsmart 4-relay board
- 2 Bosch automotive relays
- Kensington tech “Paticle beacon”
and the following software:
- Bash script that runs on startup and energizes one of the relays on the sainsmart relay board
- This gives the power circuit another path to ground to prevent un-intentional re-boots if the ignition switch is cycled after boot and before graceful shutdown.
- node.js script that does the following:
- runs on boot
- uses setInterval to check if the vehicle is running (1 of the Bosch relays sends a signal from the vehicle’s “run” circuit to the GPIO interface)
- If the vehicle is running, start a timer. If the BTLE device (uniquely identified by the device UUID)is detected, reset the timer.
- If no device is detected, energize a relay on the sainsmart board to cut fuel.
- If no “running” signal is detected for 30 minutes, gracefully shut down Pi.
That pretty much sums it up very briefly. If you’re interested in more details, please do let me know.
Please consider leaving a donation if you appreciate this information. Lightning network now available
[…] Over-complicating things is one of my favorite things to do and over-complicating something as simple as a toggle switch? How does one even do that…read on. […]