Monday, July 06, 2015

OBD Oh Bee Dah

Hey there's an ODBII Bluetooth device on sale cheap. I think I'll get it and play around.

It's here! (After a couple of weeks. I actually forgot I bought it.)

There's many smartphone apps for ODB devices. Oh, not so many use Bluetooth. Oh, iPhone Bluetooth is a special problem.

But, hey, it's hardware that is soft and I have some skill and making ware that is soft. So let's look around.

Wow. OBD protocol use AT commands just like those Hayes modems from the 80s.

Look, there's some github repos with Python OBD libraries. That one looks interesting; fork it. Look there's one forked from it that adds tests. Let's fork that one instead. Hmmm. Github won't let me fork that one because I have already forked the one it was forked from.  Looks like I can add a Learning Item for how to get and compare different forks of repositories. But not now. Just deleting the thing I forked and forking the one with tests. Now I've got it.

{the above was my recollection of the history to this point. the rest is an as-it-happened account.}

It recommends using virtualenv when running the tests. Okie Dokie. pip install it. Wait: errors. Try a couple of more things. Hit the Googles.

Ah, nice. Upgrading to the new OSX probably borked all the Python installations. When using the bundled Python, upgrading OS X can nuke your Python packages, forcing you to re-install them."

brew install python

Errors errors errors...

The Googles say we must uninstall homebrew, too. Bah. More complicated that it should be. And then more errors and more fixes (delete some folders).

Install homebrew. Gah. More errors and more fixes (change permissions on some folders).

Finally, homebrew is installed. I'll just check it out a bit:

brew doctor

ERRORS. Some errors, some errors, and new newer version of XCode....and install those updates..brew doctor...errors...follow suggestions to clean them up...brew doctor...finally clean.

And at last 'sudo pip install virtualenv' works.

Now follow the project's github page instructions on running the tests. Activate the virtualenv, install pytest, run the setup, run the tests. Errors. hmmm.

Poke googles, prod, try again, and again, and oh good. 'python setup.py install' requires that the source folder be the current working directory. I tend to put all my projects in a 'PROJECT/source' folder structure and try not to run executables in the source folder. This setup.py assumes that the current working directory is the base source folder of the project.

But now I have green tests and can start playing.

import obd
obd.debug.console = True
connection = obd.OBD()
r = connection.supported_commands
print r


(python-OBD)Butchs-MacBook-Pro:examples butchhoward$ python list_supported_commands.py
[obd] ========================== python-OBD (v0.4.0) ==========================
[obd] Using scanSerial to select port
[obd] Available ports: ['/dev/tty.OBDII-SPP']
[obd] Attempting to use port: /dev/tty.OBDII-SPP
[obd] Opening serial port '/dev/tty.OBDII-SPP'
[obd] Serial port successfully opened on /dev/tty.OBDII-SPP
[obd] write: 'ATZ\r\n'
[obd] wait: 1 seconds
[obd] __read() found nothing
[obd] __read() found nothing
[obd] __read() never recieved prompt character
[obd] read: ''
[obd] write: 'ATE0\r\n'
[obd] __read() found nothing
[obd] __read() found nothing
[obd] __read() never recieved prompt character
[obd] read: ''
[obd] Connection Error:
[obd]     ATE0 did not return 'OK'
[obd] Failed to connect
[obd] =========================================================================


Hmmm. Now is it the library, the car, the OBDII device, or the Mac BlueTooth that is the problem.

Then my son comes over. He has an Android device. We put one of the free ODB apps on it and it works. So, the problem is either the Mac or the library.

Now that we have it working with something, it puts a damper on my motivation for playing around with the library. Maybe it will revive later this week.


No comments: