Archived:How to scan Bluetooth devices for supported profiles
Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
Article Metadata
This code sample is used on a PC to scan for local Bluetooth devices and list the supported profiles using PyBluez [1]. This code will find most Bluetooth devices including; laptops, Bluetooth dongles, audio devices and mobile phones.
Close other applications using the local Bluetooth device such a PC Suite before scanning.
# btprofiles.py
#
# Requires Pybluez from Google
# http://code.google.com/p/pybluez/
# PyBluez works on GNU/Linux and Windows XP (Microsoft and Widcomm Bluetooth stacks)
#
# Scan for devices and List Bluetooth profiles supported by a device
#
# October 21, 2008
import sys
import bluetooth #Pybluez http://code.google.com/p/pybluez/
deviceAddress = None
while True:
deviceName = []
foundDevices = bluetooth.discover_devices()
for count, bdaddr in enumerate(foundDevices):
deviceName.append(bluetooth.lookup_name( bdaddr ))
print "%2d %-16s Address: %s" % (count +1, deviceName[count], bdaddr)
choice = raw_input("Choose Device or 0 to repeat scan")
# Repeat scan to get more device names
if choice.isdigit() and int(choice) <= len(foundDevices):
choice = int(choice)
if choice > 0:
print "\n-- Select device, 0 to repeat scan or q to quit --\n"
selected = deviceName[choice -1]
deviceAddress = foundDevices[choice -1]
if deviceAddress is not None:
else:
print "Could not find a Bluetooth device"
break
elif choice in ("q", "Q"):
sys.exit(0)
services = bluetooth.find_service(address=deviceAddress)
devicename = bluetooth.lookup_name(deviceAddress, timeout=10)
showProfiles = None
if len(services) > 0:
print "Found %d services on %s\n" % (len(services), deviceAddress)
#
else:
print "No device found at address: %s" % deviceAddress
print "Did you turn on bluetooth?"
print "Did you accept/authorize the connection?"
sys.exit(3)
dunPort = 0 # Not found yet
# Get Service Details
# global showProfiles
showProfiles = raw_input("Show Bluetooth Profiles supported? y|n")
for svc in services:
# Look for DUN port
if svc["name"] == "Dial-Up Networking":
dunPort = svc["port"]
if showProfiles == "y":
print "BT Profile: %s" % svc["name"]
print " Host: %s" % svc["host"]
print " Description: %s" % svc["description"]
print " Provided By: %s" % svc["provider"]
print " Protocol: %s" % svc["protocol"]
print " channel/PSM: %s" % svc["port"]
print " svc classes: %s "% svc["service-classes"]
print " profiles: %s "% svc["profiles"]
print " service id: %s "% svc["service-id"]
if dunPort != 0:
print "Found Dial-Up Networking port = %d" % (dunPort)
sys.exit(0)
else :
print "Could not find Dial Up Networking port."
print "Or DUN port is busy."
print "Switch the target's Bluetooth off then on and retry"
sys.exit(4)


(no comments yet)