Python
  Home arrow Python arrow Page 3 - Bluetooth Programming using Python
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
eWeek
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Bluetooth Programming using Python
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2007-09-10

    Table of Contents:
  • Bluetooth Programming using Python
  • Bluetooth and Python: the Whys and Wherefores
  • Bluetooth Programming, Step by Step
  • Bluetooth Programming in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Bluetooth Programming using Python - Bluetooth Programming, Step by Step
    (Page 3 of 4 )

    For whatever profile the programming is being done, there are two main steps that one has to follow. They are:

    1. Discovering devices in range
    2. Looking up the human readable name

    One point to keep in mind is that both of these are probabilistic, i.e. sometimes these steps may fail on the first attempt. Hence, it is a good idea to repeat these steps twice or thrice before deciding that there are no devices nearby.

    Discovering Devices in Range

    The first step is to find the devices that are in range so that a connection can be established with them. This is known as the discovery of devices. To discover devices in range, one needs to call the discover_devices() method. It returns a list of addresses of devices discovered. For example, the following statement discovers devices in range and returns a list of such devices:

    discovered_devices = discover_devices()

    Looking up the human readable name

    The addresses of the discovered devices are of the form "XX:XX:XX:XX:XX" where each X is a hexadecimal character representing "one octet of the 48-bit address." However, to actually access the device with which one needs to communicate, one should know the "human readable format" of the address. One of the main reasons is that a person gives a name that he or she can remember for a particular device, and it's easier to match with that name rather than a 48-bit address for the same.

    To get the human readable format one can use the lookup_name() method. It accepts the address of a device and returns its user friendly or human readable format. For example, to find a device named "Raj" from the list of the of return addresses the code would be:

    target_device = "Raj"
    target_device_address = None

    for address in discovered_devices:
       if target_device==lookup_name(address):
          target_device_address=address
          break

       

    if target_device_address is not None:
       print "The address of the target device is :",
    target_device_address
    else:
       print "Could not find address of target device"

    The code iterates over the list of addresses and passes one address at a time to the lookup_name method. Then it compares the returned name with the desired device name. if it matches, a message is printed and the method breaks out of the loop.

    That completes the basic steps required to connect to any device. Once the discovery is done, then based on type of service, communication can begin. Now that the steps are clear, let us look at a real world example that uses the steps just detailed to access a Bluetooth device.

    More Python Articles
    More By A.P.Rajshekhar


       · In this discussion I have tried to introduce the basics of Bluetooth programming...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway