Python SDK for Pi's car monitoring and using the OBD2 cloud storage service
Python PHP Shell
Switch branches/tags
Nothing to show
Clone or download
Latest commit 5db6a51 Dec 10, 2015
Permalink
Failed to load latest commit information.
.gitignore ignoring compiled python files Dec 28, 2013
README.md changed db name Dec 10, 2015
client.py removed unneeded APIKey from function arguments Jul 18, 2014
client_gps.py bugfix in sdk and updated the client to send the right data. Jan 11, 2014
config.txt changed default logging to 1 second, added log file, added new daemon… Nov 24, 2014
events.log changed default logging to 1 second, added log file, added new daemon… Nov 24, 2014
gps.db cleared test data out of default gps db Nov 23, 2014
gps_main.py added Python's logging framework to log errors to events.log. Changed… Nov 24, 2014
gps_main_GPSLib.py GPS daemon that uses 'import gps' GPS library which doesn't work depe… Jan 18, 2014
gpslogger.conf removed the 2nd python script Nov 24, 2014
gpssync.conf changed default logging to 1 second, added log file, added new daemon… Nov 24, 2014
index.php added link to dashcam files on local Pi page Mar 26, 2015
jnsdk.py added Python's logging framework to log errors to events.log. Changed… Nov 24, 2014
motion.conf added MOTION config file Mar 26, 2015
obd.db put OBD data into it's own db. sqlite doesn't handle concurrency for … Jan 22, 2014
setup.py changed default logging to 1 second, added log file, added new daemon… Nov 24, 2014
setup.sh added a general update of entire system to the start of the process. Nov 24, 2014
sync.py commented out mongo Jan 28, 2014
sync_MongoDB.py the Mongodb version of the sync script Jan 22, 2014
sync_gps.py turned off upload confirmation. was too verbose Nov 24, 2014
sync_gps_MongoDB.py the mongodb version of sync which reads from a MongoDB buffer Jan 21, 2014

README.md

OBD2SDK_Python

Python SDK for using the OBD2 cloud storage service

Main project page: http://www.blackboxpi.com

The OBD2 cloud storage service is available here: https://github.com/BizDevGeek/OBD2CloudStorage

This project contains an SDK that you can use to save OBD2 PID values. Use it with existing Python based OBD2 capture software such as the popular "pyobd". Any time a PID is logged from the computer, save it using the SDK so that it gets stored in the cloud storage service.

The SDK stores the saved values in a local buffer. The buffer is a MySQL collection.

GPS data is also being added in. This feature is still in development.

sync.py pulls records from the local buffer and sends them to the API via JSON. It then removes them from the buffer. Runs in an infinite loop, not just until the buffer is empty. You can run it in a separate terminal window and leave it going, or Ctrl+C to kill it.

The date/time reported to the cloud service is based on the Pi's local time and timezone. Make sure this is set properly. You can run "sudo raspi-config" to set the timezone on your Pi. In future versions, the UTC clock returned by the GPS may be used, although this can also have issues.

Installation

SSH into your Raspberry Pi

Make sure it's up to date:

sudo apt-get update

sudo apt-get upgrade

Install the various pre-requisites:

sudo apt-get install gpsd gpsd-clients python-gps python-serial sqlite3

cd /home/pi

Copy the SDK from GitHub to the Pi:

git clone https://github.com/BizDevGeek/OBD2SDK_Python.git

Run the setup program. This gets you an API key from the cloud service, sets the names of the databases, and the device path to an optional GPS device. The config data is saved to config.txt. You can use all the defaults to keep it simple.

python setup.py

Install the GPS daemon so that it's recording GPS data into the local buffer. The daemon uses "upstart" instead of /etc/init.d, the latest method of managing services in Linux.

sudo cp /home/pi/OBD2SDK_Python/gpslogger.conf /etc/init

sudo service gpslogger start

If you're installing the API to your own server, make sure that's setup first. You'll need the URL for the next step. EX: http://23.239.10.88/obdapi/. If you don't have this setup, a default server is provided for you.

setup.py - Prompts you for the server URL (or use the author's for default) and for an email address and returns an API Key for you to use. It creates the config file below.

config.txt - Created by setup.py. Contains the URL of the API server and your API Key for the SDK.

Using the SDK

Copy the .py files to where your Python program is.

In your Python program, add "import jnsdk". To save a PID each time you poll it from the OBD2 serial connection: jnsdk.SendPID(jnsdk.APIKey(), PID, PIDValue)

The above function call saves the PID values to a local buffer, a MySQL database. Run sync.py to sync the data to the API. It pulls records one at a time from the buffer, uploads to the API, then removes them. It verifies that there's a connection to the server first.

The GPS daemon gpslogger reads the Pi's serial connection to the USB GPS device and logs it to local buffer. Run sync_gps.py to sync the data from local storage buffer into the cloud.