A Vinli Tech Hack that Fixed My Forgetfulness

This guest post is courtesy of Kiefer Waight. He’s a Software Consultant at the Great Wolf Lodge, and COO/Cofounder at Appealing Studio. Enjoy.

What?

I wrote a server based script that monitors my cars stats and alerts me via text message whenever the car is running and the fuel meter dips below 15%. Just to be super annoying, I have it send a text message every 5 min.

Why?

Back in October my family and I purchased a new vehicle. Our old Yukon was getting way too cramped with 4 car seats. In addition, we were expecting our 5th child.

I know what you’re thinking. This is usually the point when people tell me the most original joke ever “You know how that happens, right?”. Yes, Yes I do…

We ended up purchasing a Nissan NV 3500 passenger van. We like to tow our 30″ travel trailer for business and it had more than enough power. It is a commercial vehicle, so some of the bells and whistles of a normal vehicle are missing. For us, generally, that was just fine. There was just one problem. In the old car, when you started it, the navigation screen would show a fuel alert if you were low. That was perfect for those late evenings where I thought “OH, I’ll just fill up tomorrow”. But, knowing me, I always rush out of the house in a hurry and completely forget.

I ran out of fuel a total of 4 times within 2 months. One of them when I was in Wisconsin. The rest were all conveniently as far from a gas station as possible.

Like every problem I have, I turn to code.

How?

I tested tons of different OBD2 adapters on the marketing. These are basically devices that plug in under your car’s dash and read your vehicle’s stats.

Long story short, Vinli was the best one. The others were a nightmare and had some of the most ridiculous hoops you had to jump through, only to find out that it didn’t have the features you need.

I ordered mine through Vinli’s distribution partner Meineke here.

Once it arrived, I popped it into the dash, downloaded the Vinli app, and followed the steps to get it synced to my car. It had me setup an account and link my device/car and setup onboard wifi (The kids love Netflix 😀 ).

Show me the code!

Now to the good stuff. Vinli has a developer portal where you can create a developer account and register an API key. This is important if you want to write any custom code against your adapter. Out of the box, there’s already a ton of functionality with the multiple apps in the vinli app store. I personally, had a specific need. I nabbed my API key and began to download the vinli CLI (Command line interface).

So with the command line interface I was able to connect my developer account to my car/adapter. You can find detailed instructions on how to do this on the Vinli blog. I’ll cover the basics. Use the code on your adapter, and login with the same credentials you used during setup.

> vinli auth add-device --case-id=XXXXXX

Add Device:email: test@test.com
Add Device:password: *******
Add Device:caseId: (XXXXXX)
Add Device:name: Kiefers Car

Signing in to test@test.com MyVinli account...
Authenticated user. Adding device...
    Device Added

Now your device is connected to your developer account.

Next I setup a quick PHP script that would run on my AWS server. Using a cron job, I scheduled it to run every 5 min. They [Vinli] didn’t have a PHP SDK, so I wrote one of those too.

<?php

//Requires composer to be installed
//composer require "appealingstudio/php-vinli-sdk":"dev-master"
//composer require twilio/sdk

require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload

use Vinli\Client;

//Lets load everything up
$vinli = new Vinli\Client("***","***");
$devices = $vinli->getDevices();

//I only have one device
$myDevice = $devices[0];

//We just want the fuel level and RPMS
$fuelSnapshots = $myDevice->getSnapshots(['fuelLevelInput']);
$rpmSnapshots = $myDevice->getSnapshots(['rpm']);

//Lets just get the lastest snapshots
$fuelLevel = $fuelSnapshots[0]->data->fuelLevelInput;
$rpms = $rpmSnapshots[0]->data->rpm;

//Just so we know it's working
echo "Fuel Level Is " . $fuelLevel;
echo "\r\nRPM is " . $rpms;

//Ok, is the car running and is fuel low?
if($rpms > 100 and $fuelLevel < 15){
    //Send text message
    $client = new Twilio\Rest\Client("***", "***");

    //And off we go
    $client->account->messages->create(
        '1231234567',
        array(
            'from' => '1231234567',
            'body' => 'Hey there! Your running low.'
        )
    );
}

The script runs every 5 mins and checks the Vinli API for the ‘fuelLevelInput’ and the ‘rpm’. I don’t want it to notify me when my car is not running, thus the RPM level was a quick way to test if the car was on. My van idle’s at 600.

If the fuelLevelInput is less than 15% and RPM is greater than 100, then send SMS.

Overall, It was a pretty easy task to get everything hooked up. I’ve not ran out of gas yet and it’s 3 months and counting. Since it runs every 5 mins, I usually get a notification by the time I leave the neighborhood.

You can download the code here

Interested in having your posts syndicated at Launch DFW? Here are the requirements!

Like this story? Share it! Subscribe to our newsletter and consider supporting us directly with as little as $1/mo. Learn more at Patreon.

Share This