| Reply | « Previous Thread | Next Thread » |
|
Hi
I made a small proof of concept over the last 4 days: had to learn python ![]() If one has a "modern" car, then it has an obd-ii connector ( http://en.wikipedia.org/wiki/On-Board_Diagnostics ) If one has a Symbian phone and a bluetooth obdii device based on an ELM device (http://www.elmelectronics.com/), it is possible to write a python script: for example to see what the warning engine red light means. Here is my first attempt Code:
# Bluetooth ELM
# first attempt
# by Owen Brotherwood, DK
import appuifw
import socket
import e32
import time
initELM = [ "atz\r", "ate0\r", "atl0\r", "ats0\r" ]
cmds = [ "atrv\r", "0100\r", "0101\r", "03\r" ]
def bt_connect():
sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
target=''
if not target:
address,services=socket.bt_discover()
print "Discovered: %s, %s"%(address,services)
if len(services)>1:
choices=services.keys()
choices.sort()
choice=appuifw.popup_menu([unicode(services[x])+": "+x
for x in choices],u'Choose port:')
target=(address,services[choices[choice]])
else:
target=(address,services.values()[0])
print "Connecting to "+str(target)
sock.connect(target)
return sock
def readbt(prompt = ">" , time = 5):
global sock, data, running, timer
line = d = ""
timer.after(time, subtout)
while running == 1:
d = sock.recv(1)
if timeout != 1:
timer.cancel()
else:
return ""
if d == 0:
continue
if d == "?":
return ""
if d == prompt:
return line
else:
line += d
def subtout():
global sock, timeout, timer, running
timer.cancel()
timeout = 1
if running == 1:
sock.send("atz\r")
def start():
global timer, sock, timeout
for init in initELM:
sock.send( init )
line = readbt() # and throw away ...
for cmd in cmds:
if running == 1:
sock.send( cmd )
else:
return
line = ""
line = readbt()
if timeout == 0:
print line, # or put in a dictionary ...
else:
print "T-T-TIMEOUT"
timeout = 0
start()
def quit():
global sock, running, script_lock
running = 0
script_lock.signal()
#appuifw.app.set_exit()
# Symbian setup
script_lock = e32.Ao_lock()
timer = e32.Ao_timer()
appuifw.app.exit_key_handler = quit
appuifw.app.title = u"BT ELM DTC Reader"
# some globals
running = 1
timeout = sock = 0
sock = bt_connect()
if sock != 0:
start()
sock.close()
script_lock.wait()
#==========================================
I doubt the app will ever be really graphical with graphs etc.: just data to aid if one is driving on holiday and the light goes on. Another branch would be that the app can send an sms when the wife is driving the car: then I can say "stop" if it is a bad error ... If you "need this" and can python and want to help: post. I'll probably make a sourceforge project if there is anybody intrested. Referance to elm : http://www.elmelectronics.com/DSheets/ELM327DS.pdf |
|
|
|
http://www.cs.unm.edu/~donour/cars/pyobd/ contains some nice work in python that only needs a small change from serial I/O to Bluetooth I/0
However ... my 4 days py60 experience is not enough in finding out how to use a module/file. I copied some files over into the python script dir on my phone: obd_io.py wants to import obd_sensors but I get an error. I think I need some library/module path but don't know how ... I don't want to make one big script file: but if there is no other way ...Any help would be aprieciated Code:
import obd_sensors from powertrain_codes import pcodes from network_codes import ucodes Edit: reading http://docs.python.org/tutorial/modu...tandardmodules Edit: solved @ http://www.johnny-lin.com/cdat_tips/...lang/path.html import sys sys.path.append("e:\python") Edit: pys60 doesn't seem to cwd to the dir of the script - it is e:\private\<something> => sucks http://www.webdotdev.com/nvd/article...n-867-204.html
Last edited by owen-oxo : 2009-03-09 at 18:55.
Reason: HOWEVERr
|
|
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Q: How to use NCF 1.2 bluetooth with S60 3rd Edition for Symbian C++ MR | jimgilmour1 | Bluetooth Technology | 35 | 2009-04-11 15:36 |
| Bluetooth on Symbian S60 3rd Edition FP1 Emulator | Shilpa_Walvekar | Bluetooth Technology | 0 | 2009-03-04 10:08 |
| ans: here is Symbian Error codes whilst using bluetooth debug and porting | jimgilmour1 | Bluetooth Technology | 0 | 2006-07-30 08:50 |
| Q: How do I program bluetooth using S60 symbian C++ A:documents here | jimgilmour1 | Bluetooth Technology | 0 | 2006-07-25 16:45 |
| whic version of symbian is required for bluetooth application development | venkatareddy | Bluetooth Technology | 3 | 2005-04-07 14:55 |