| Reply | « Previous Thread | Next Thread » |
|
Hello to everybody,
I want to know does it possible to make a bluetooth application on a phone which is developped on Python language ? Thanks |
| the_talented |
| View Public Profile |
| Find all posts by the_talented |
|
Download and review Python for Series 60 Documentation bundle at http://forum.nokia.com/main/0,6566,0...ml&fileID=6534
At "Programming with Python for Series 60 Platform" there is section dedicated to the topic - Bluetooth Sockets. There is example of services discovery and reference to Python's Bluetooth console and Bluetooth socket stdio. May be some other examples would be useful. ;-) |
|
Hi,
Here is a sample BT program that reads a position from a BT GPS and displays it. import socket class BTReader: def connect(self): self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM) address,services=socket.bt_discover() print "Discovered: %s, %s"%(address,services) target=(address,services.values()[0]) print "Connecting to "+str(target) self.sock.connect(target) def readposition(self): try: while 1: buffer="" ch=self.sock.recv(1) while(ch!='$'): ch=self.sock.recv(1) while 1: if (ch=='\r'): break buffer+=ch ch=self.sock.recv(1) if (buffer[0:6]=="$GPGGA"): (GPGGA,hhmmssss,l1ddmmmmmm,l1,l2dddmmmmmm,l2,q,xx,pp,ab,M,cd,M,xx,nnnn)=buffer.split(",") return (l1+l1ddmmmmmm, l2+l2dddmmmmmm) except Error: return None def close(self): self.sock.close() bt=BTReader() bt.connect() print bt.readposition() print bt.readposition() print bt.readposition() bt.close() |
|
I am aware that the above is oversimplification, but yet I would like to point out that:
GPGGA is not enough to read GPS position, with all receivers, since not all receiver use it. I think you should be able decode at least : GPGGA GPRMC GPGLL messages. Possible others, I have only practical xp on subject. One other thing is that __some__ receivers and sending some of the above messages without cordinates, if they do not hear satellites. You should not crash on it. Just because your code work with one NMEA receiver does not meat that it works with them all. |
|
You' re right, but I didn't pretend it to be very robust always working code. For example, in the same GPGGA string the validness etc is also stored but not used in the code.
My BT GPS unit only sends GPGSA, GPGSV, GPGGA and GPRMC strings, which again shows that different unit use different parts of the standard! |
|
I have been trying to make a socket connection over bluetooth to a Bluez enabled GNU/Linux box, without much luck.
Is there any more information on the Python bluetooth interface, than in the 3 pdf's? I would like more examples :) |
|
Quote:
|
|
Is someone can check out if indentation is OK ???
Code:
import socket
class BTReader:
def connect(self):
self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
address,services=socket.bt_discover()
print "Discovered: %s, %s"%(address,services)
target=(address,services.values()[0])
print "Connecting to "+str(target)
self.sock.connect(target)
def readposition(self):
try:
while 1:
buffer=""
ch=self.sock.recv(1)
while(ch!='$'):
ch=self.sock.recv(1)
while 1:
if (ch=='\r'):
break
buffer+=ch
ch=self.sock.recv(1)
if (buffer[0:6]=="$GPGGA"):
(GPGGA,hhmmssss,l1ddmmmmmm,l1,l2dddmmmmmm,l2,q,xx,pp,ab,M,cd,M,xx,nnnn)=buffer.split(",")
return (l1+l1ddmmmmmm, l2+l2dddmmmmmm)
except Error:
return None
def close(self):
self.sock.close()
bt=BTReader()
bt.connect()
print bt.readposition()
print bt.readposition()
print bt.readposition()
bt.close()
Cyke64 pys60 1.4.5,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 ! pys60 extension modules on http://cyke64.googlepages.com/ |
|
Quote:
yes there is an error in indentation after try. you should give a space before while |
|
Thanks Sagars
![]() Cyke64 pys60 1.4.5,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 ! pys60 extension modules on http://cyke64.googlepages.com/ |
|
can this be done more simply with pybluez??
|
| sarathgopalr |
| View Public Profile |
| Find all posts by sarathgopalr |
|
Quote:
Indentation is still not correct but the example is overly complicated anyway. There is no need to read char by char and parse line ends, you can easily use socket.makefile() and use readline() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |