Software apps and online services
I'm glad you asked! There are numerous reasons to monitor a fleet of vehicles. Some organizations just want to track location, which is essentially just asset tracking, while others want to monitor the health of a vehicle. This can be helpful when needing to ensure that your vehicles are getting the maintenance they need. This improves safety and provides an insight into how to improve operations. It also helps in deploying a vehicle to where it can best serve.Wow! That's so cool! But how can I, a humble maker, build something so complicated?
Easy! For the next couple of weeks I'm going to be documenting my journey as I set out to build a DIY solution using off-the-shelf maker friendly hardware. I've already listed the bare minimum low-cost parts needed.The Hardware
I'll be using a USB OBDII adapter (see link above) connected to a Raspberry Pi with a standard GPS module wired to the GPIO pins. With the Hologram Nova, a USB GSM modem, I'll be able to add remote connectivity to the vehicle tracker. Hologram.io provides amazing coverage at a very maker friendly cost. Best part is, someone could easily take this hack and turn it into a product ready to deploy.The Software
There are two parts to this.
The first being the piece of code that runs to collect relevant information from the OBDII reader periodically and couples it with GPS data to then send as a data message through the Hologram.io network.
In the interest of transparency, I'm working through building this in nodejs, however the OBD-II libraries seem to be very outdated, so the first hurdle is writing out a useable implementation using the node-serialport library. If node doesn't work out this part might get built in python! If anyone reading this happens to have had experience with this, please reach out!
If you want to follow along and perhaps even help contribute, you can order the exact parts and contribute to the GitHub project!A few takeaways before we begin..
- Node.JS didn't work out. I spent a lot of time trying to get the node libraries working and found that a lot of them had been neglected a long while and with so many version changes of node in that time, a few things didn't work out as efficiently. So I've switched to Python, which I think is better for beginners as it has less dependancies.
- I started off with what I didn't realize was a knockoff of the USB ScanTool OBDII reader. This caused some compatibility issues as it had no firmware support. I reccomend using this one https://www.amazon.com/gp/product/B005ZWM0R4/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
- There are some OBD-II simulators out there. Those would have been very useful in development. I have a '94 Land Cruiser, which does not have an OBD-II port. Womp womp
- Instead of spinning up our own MQTT broker and creating a dashboard from scratch, I went with Adafruit.IO - which provides an IoT messaging broker as well as a Dashboard platform.
- Instead of using a GPS module, we're using the Hologram Nova module to ping the location of the nearest cell tower.
Alright, with that in mind, lets get started!
THE PART OF THE GUIDE THAT MATTERS
Get your Hardware Ready
You should have:
- Raspberry Pi 3
- Hologram Nova USB Modem
- ScanTool USB OBD-II Reader
- FTDI Cable (Optional if you just want to use a Monitor and Keyboard)
- USB Powersupply (with a car adapter if you intend to use it in your car)
Burn the latest Raspbian image to a raspberry pi. I recommend Etcher.io - Its a lightweight tool that figures out all the magic of burning an image to an SD card.
You can find the latest image here. Choose whatever flavour works for you.Setup Hologram Nova
You'll need a Hologram.io account to provision your SIM card that comes included with your Nova. All you really need to do is activate your SIM card since we won't be using the Hologram data routers. We will be using the Python SDK to get the cell tower location and the Hologram CLI to connect to the internet so we can relay information to Adafruit.ioPlug in the ScanTool and Nova to your Pi
This requires a mastery of USB ports. Not for the faint of heart.
Go to Adafruit.io and set up an account.
Goto Feeds -> Actions -> Create A New Feed and name it fleet
Goto Dashboards and create a new dashboard.
Start by adding a Map view. Set Hours of History to 9999 for a full historical view of GPS locations.
Repeat this with the Dial module. Use the same feed, we send both sensor value and GPS location up in the same message, it grabs the first value sent and display it, which in our example is Speed.
Grab your AIO Key and stash it for when we run the code. There is a link from the main page.
If you are more curious about the API or the dashboard visit these links.
There are a few ways you can do this.
- Monitor and Keyboard
- TTY over serial
I prefer serial because it makes it easier when you are working out of a car and don't have wifi. Adafruit has a great guide on that https://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/
ProTip: On the Pi 3, when bluetooth is enabled it interferes with the serial pins. Mount the SD card on a computer and edit the config.txt file and add this line.
Lets get this code going!
Finally! Lets do this!
All the code and instructions can be found at the github repository here https://github.com/HologramEducation/hologram-vehicle-monitorInstallation
Run the Example
curl -L hologram.io/python-install | bash curl -L hologram.io/python-update | bash sudo pip install adafruit-io sudo pip install obd
- Clone this repo
git clone https://github.com/HologramEducation/hologram-vehicle-monitor
- Create a file adafruitConfig.py with the following:
ADAFRUIT_IO_KEY = 'YOUR ADAFRUIT IO KEY' ADAFRUIT_IO_USERNAME = 'YOUR ADAFRUIT IO USERNAME'
- Spin up the network connection through the NOVA
sudo hologram network connect
- Plugin the other end of the OBD ScanTool to an active vehicle.
- Start the script
So you'll notice every two minutes data is being sent to the Adafruit cloud. You can change this interval by editing the sleep time at the bottom of the main.py script.
Now go to your adafruit dashboard, you should see the map hone in on your location and the dial should show the speed of your vehicle!
I hope you enjoyed this project and I hope you'll help contribute and share what you do with it! This was my first time creating a Python project so I'm sure it can be improved!OBD-II Commands - What else can you do?!
The main example send up values returned from the SPEED command. Below is a basic example of how to use the OBD python library.
Here is a link to all the supported commands: https://github.com/brendan-w/python-OBD/blob/master/docs/Command%20Tables.md
Give different ones a shot and see if there is data that you might find more useful from your vehicle.
import obd connection = obd.OBD() # auto-connects to USB or RF port cmd = obd.commands.STATUS # select an OBD command (sensor) response = connection.query(cmd) # send the command, and parse the response print(response.value) # returns unit-bearing values thanks to Pint