You Are Here:

Community: Developer Discussion Boards

#1 Old Programming Bluetooth aplication by Python - 2005-01-08, 10:45

Join Date: Jan 2005
Posts: 1
the_talented
Offline
Registered User
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
Reply With Quote

#2 Old 2005-01-08, 19:52

Join Date: Jan 2005
Posts: 7
mkol5222
Offline
Registered User
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. ;-)
Reply With Quote

#3 Old example BT program - 2005-01-09, 23:40

Join Date: Dec 2004
Posts: 10
Location: Groningen, Netherlands
zechgron
Offline
Registered User
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()
Reply With Quote

#4 Old 2005-01-14, 12:23

Join Date: Feb 2004
Posts: 119
jkekoni
Offline
Regular Contributor
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.
Reply With Quote

#5 Old 2005-01-16, 11:37

Join Date: Dec 2004
Posts: 10
Location: Groningen, Netherlands
zechgron
Offline
Registered User
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!
Reply With Quote

#6 Old Connecting to Bluez - 2005-01-16, 20:53

Join Date: Jan 2005
Posts: 1
sverrejoh
Offline
Registered User
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 :)
Reply With Quote

#7 Old Re: Connecting to Bluez - 2005-01-17, 10:24

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
Quote:
Originally posted by sverrejoh
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
There are instructions in the postneo wiki for using Bluetooth on various platforms. See http://www.postneo.com/postwiki/moin...honForSeries60
Reply With Quote

#8 Old Re: Programming Bluetooth aplication by Python - 2007-04-03, 12:51

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
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()
Thanks
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/
Reply With Quote

#9 Old Re: Programming Bluetooth aplication by Python - 2007-04-03, 13:28

Join Date: Nov 2006
Posts: 186
Location: Pune, india
sagars's Avatar
sagars
Offline
Regular Contributor
Quote:
Originally Posted by cyke64
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()
Thanks
Cyke64

yes there is an error in indentation after try.
you should give a space before while
Reply With Quote

#10 Old Re: Programming Bluetooth aplication by Python - 2007-04-03, 19:35

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
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/
Reply With Quote

#11 Old Re: Programming Bluetooth aplication by Python - 2007-06-20, 08:04

Join Date: Jun 2007
Posts: 13
sarathgopalr
Offline
Registered User
can this be done more simply with pybluez??
Reply With Quote

#12 Old Re: Programming Bluetooth aplication by Python - 2008-03-25, 21:17

Join Date: Mar 2008
Posts: 2
NeoT
Offline
Registered User
Quote:
Originally Posted by cyke64 View Post
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()
Thanks
Cyke64

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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia