| Reply | « Previous Thread | Next Thread » |
|
Hi all,
I want to know all the services of the bluetooth devices discovered, I hear that this is possibe find these info analyzing the MAC address of each device (I have already this information). someone knows in witch manner can I use it? is there another possibility? tanks, jon |
|
Hello.
The Bluetooth specification does not use the acronym MAC to refer to unique device identifiers. It uses the word BD_ADDR instead (Bluetooth Device ADDRess). BD_ADDR does not contain information about the device's abilities. It is a sequential number assigned by the device manufacturer. There may be ranges of BD_ADDR which all contain a specific type of device, but that is a manufacturer specific artifact. All Bluetooth devices contain another number, the device class. It is a bitmask of capabilities and roles the device has. The device class is often used by other devices to decide if its worthwhile to further establish an SDP connection and read the detailed capability records. Unfortunately, there seems to be no way to get Bluetooth device class in PyS60 version 1.3.17 and below. |
|
Series60 Python includes a number of Bluetooth extensions to the standard socket module. To discover which services a Bluetooth devices affords, simply call the function bt_discover(). This has one optional argument of a device address, and if this is not provided, it launches the BT discovery dialog on the phone. It returns a pair, the address of the device and a dictionary of the device's services.
For example, here's some code I used to discover and connect to a BT GPS device. Code:
import appuifw, e32, nmealib, socket, time
def connectGps():
# MAC of GPS unit here, e.g.
#gpsMac = '00:0B:0D:19:1E:6E'
gpsAddr = ''
# open a BT socket
s = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
if not gpsAddr:
# use a built-in BT service discover to find nearby devices
address,services = socket.bt_discover()
print "Discovered: %s "%(address)
print "Services: %s" %(services)
gpsAddr = address
# Start serial connection to GPS
target = (gpsAddr,1)
s.connect(target)
print 'Connected to the GPS'
parseGps(s)
Update: Reading Jethro's response, I perhaps might have misunderstood your question. If so, sorry if my response is confusing. But perhaps it will still be useful, to you or someone else.
Last edited by andersnc : 2007-02-14 at 19:46.
|
|
sorry but my question was not very clear.
I want to know for example if the devices is a laptop, a PC or a mobile phone. I saw in this link (http://www.jasonlam604.com/articles_...j2me_part2.php) in the second table is show that if I will know the Major Class and Minor Class I will find the type of device detected. I hope that now the problem is clear. what can I do? |
|
Like I said, there seems to be no way to get the class of a Bluetooth device from within PyS60. Sorry!
|
|
Quote:
I hope that this can help you jon88 ![]() 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:
|
|
the problem is that with the function findservices(addr=None, name=None, servicetype=None) I will find only RFCOMM and OBEX services of each devices, so I cannot know the type of devices.
![]() |
|
Quote:
Quote:
|
|
Quote:
ok tanks very much. were I can find a complete table with all the association number-type of devices? I obtained this values: major service class - major device class - minor device class: (640, 2, 3) (16, 1, 1) (144, 1, 1) but I coudn't find this values. can you help me? tnx |
|
Bluetooth SIG (http://www.bluetooth.org) maintains Bluetooth specific standards. You need to be a member to access some of the pages. Fortunately, Google was able to bypass the registration and directly pointed to the page where device classes are documented:
http://www.bluetooth.org/assigned-numbers/baseband.htm |
|
Quote:
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/ |
|
first I want to say tnx to jethro(tull).fn nice nick
![]() now I have a new problem with my program. if I turn of my phone and I will run the program it is working fine, but if I try to run it again doesn't work. Why? I will put the code, so someone can help me. tnx a lot jon Code:
import aosocketnativenew
import appuifw
import e32
import socket
import location
from aosocket.symbian.bt_device_discoverer import *
from time import *
from pdis.lib.logging import *
from lightblue import *
import lightblue
lock = e32.Ao_lock()
PossiblePlaces = [u'University', u'Home', u'Student House', u'Station', u'Other..']
path = "c:\BT_scan.txt"
def CreateFile():
BT = open(path,'w')
BT.write(" ")
BT.close()
def Inizialization():
global GsmPosition, running, Time, Position, Xml, oldXml, finalList
running = 1
Position = ''
GsmPosition = []
finalList = []
Time = ''
Xml = ''
oldXml = ''
def start():
global running, finalList
menu1()
Inizialization()
FirstContent=''
FirstTag="BT_Discover"
WriteXmlOpen(FirstTag,FirstContent)
while (running):
print "Discovering...."
getDevices()
print "Pause...."
e32.ao_sleep(30)
def getDevices():
global finalList, Xml, oldXml, Time, Position, GsmPosition
oldXml = Xml
classDevices = []
typeDevices = []
listServicesRFCOM = []
listServicesOBEX = []
temp1 = []
temp2 = []
listServices = []
address = []
listAllDevices = []
Device = []
temp = ()
temp3 = ["No services RFCOM for this device"]
temp4 = ["No services OBEX for this device"]
getTime()
getGsmPosition()
if Position == '':
getPosition()
try:
listAllDevices = finddevices() #[(addr,name,class of services),(...),(...)]
print "I founded this devices"
print listAllDevices
finalList = []
for i in range(0,len(listAllDevices)):
print "Device"+str(i+1)+":"
print listAllDevices[i][1]
Device = [] #single devices
Device.append(listAllDevices[i][0]) #append address
Device.append(listAllDevices[i][1]) #append name
Device.append(listAllDevices[i][2]) #append class of services
temp = splitclass(listAllDevices[i][2]) #(MsCl,MdCl,mdCl)
Device.append(temp) #append (MsCl,MdCl,mdCl)
address.append(listAllDevices[i][0]) #[add1,add2,add3,...]
print Device
try:
temp1 = findservices(address[i],None,RFCOMM) #[add,num port,name service]
Device.append(temp1[0][1]) #append number of port
Device.append(temp1[0][2]) #append name services
except:
Device.append(temp3)
try:
temp2 = findservices(address[i],None,OBEX)
Device.append(temp2[0][1]) #append number of port
Device.append(temp2[0][2]) #append number of port
except:
Device.append(temp3)
print Device
finalList.append(Device)
print "The whole list of all the devices is: "+'\n'
print finalList
createListXML()
except:
print "No devices"
def createListXML():
global finalList, Xml, oldXml
a = ()
oldXml = Xml
numdevContent = "Tot devices = "+str(len(finalList))
WriteXmlOpen("NumDev",numdevContent)
WriteXmlClose("NumDev")
for i in range(0,len(finalList)):
devContent = "Dev "+str(i+1)
WriteXmlOpen("Dev",devContent)
#
nameContent = finalList[i][1]
WriteXmlOpen('Name',nameContent)
WriteXmlClose('Name')
#
addrContent = finalList[i][0]
WriteXmlOpen('Addr',addrContent)
WriteXmlClose('Addr')
#
a = finalList[i][3]
MaSClContent = unicode(a[0])
WriteXmlOpen('MaSCl',MaSClContent)
WriteXmlClose('MaSCl')
#
MaDClContent = unicode(a[1])
WriteXmlOpen('MaDCl',MaDClContent)
WriteXmlClose('MaDCl')
#
MiDClContent = unicode(a[2])
WriteXmlOpen('MiDCl',MiDClContent)
WriteXmlClose('MiDCl')
#
rfcomContent = str(finalList[i][4])
WriteXmlOpen('RFCOM',rfcomContent)
WriteXmlClose('RFCOM')
#
obexContent = str(finalList[i][5])
WriteXmlOpen('OBEX',obexContent)
WriteXmlClose('OBEX')
#
WriteXmlClose("Dev")
oldXml = Xml
def getGsmPosition():
global GsmPosition
GsmPosition = location.gsm_location()
gsmContent = "GsmLocation= "+ str(GsmPosition)
WriteXmlOpen("GsmLoc",gsmContent)
WriteXmlClose("GsmLoc")
def getTime():
global Time
Time = time.ctime()
timeContent = "Day = " + Time[0:4]+Time[8:11]+Time[4:8]+Time[-4:]+"Time = "+Time[11:19]
WriteXmlOpen("Time",timeContent)
WriteXmlClose("Time")
def getPosition():
global Position,PossiblePlaces
index = appuifw.selection_list(choices=PossiblePlaces , search_field=1)
if (index == len(PossiblePlaces)-1):
Position=appuifw.query(u'Insert Location','text',unicode(Position))
else:
Position= PossiblePlaces[index]
positionContent = "Place= "+Position
WriteXmlOpen("Place",positionContent)
WriteXmlClose("Place")
def show():
a = open(path,'r+')
print a.read()
a.close()
def WriteData(text):
a = open(path,'a')
a.write(text)
a.close()
def WriteXmlOpen(Tag,Content):
global Xml
if (Content==''):
StrOpen = "<"+Tag+">"
else:
StrOpen = "<"+Tag+">"+Content
Xml = Xml + StrOpen
def WriteXmlClose(Tag):
global Xml
StrClose = "</"+Tag+">"+"\n"
Xml = Xml + StrClose
def stop():
global running,oldXml
running = 0
menu2()
print "stopping..."
oldXml = oldXml+"</BT_Discover>"+"\n"
WriteData(oldXml)
lock.signal()
def exit_key_handler():
app_lock.signal()
appuifw.app.set_exit()
def menu0():
appuifw.app.menu = [(u"START", start),(u"EXIT", exit_key_handler)]
def menu1():
appuifw.app.menu = [(u"STOP", stop),(u"SHOW LOG", show),(u"EXIT", exit_key_handler)]
def menu2():
appuifw.app.menu = [(u"START", start),(u"SHOW LOG", show),(u"EXIT", exit_key_handler)]
CreateFile()
menu0()
appuifw.app.exit_key_handler = exit_key_handler
app_lock = e32.Ao_lock()
app_lock.wait()
|
|
ok, I solve it. I was working with the old version of python.
Now I want to know if is possible to find other service, becuse with finddevices() with python s60 it's possible to find onli OBEX and RFCOM sevices. Can I modify this function or using other modules for obtain diffrent services? I have also in same cases another problem in this part of code: Code:
try:
temp1 = findservices(address[i],None,RFCOMM) #[add,num port,name service]
Device.append(temp1[0][1]) #append number of port
Device.append(temp1[0][2]) #append name services
except:
Device.append(temp3)
try:
temp2 = findservices(address[i],None,OBEX)
Device.append(temp2[0][1]) #append number of port
Device.append(temp2[0][2]) #append number of port
except:
Device.append(temp3)
I don't understand why. If the code inside the try blocks gives a exception, why is not execute the code inside the except blocks? tnx all
Last edited by jon83 : 2007-02-23 at 16:53.
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| how to retrieve mac address of wlan interface | madsum | Symbian Networking & Messaging | 6 | 2007-12-28 15:04 |
| MAC address of E60 - for WLAN filtering? | kja2615 | Wired and Wireless interfaces | 1 | 2006-11-15 10:59 |
| IP Address? Mac Address | Pit | Wired and Wireless interfaces | 1 | 2006-09-29 18:25 |
| How to get a device's bluetooth address before I connect to it. | doglovecat527 | Symbian Networking & Messaging | 0 | 2005-09-02 08:50 |
| How to Query Remote Device's name and Local Devices Address | janneromppanen | Bluetooth Technology | 1 | 2002-07-15 10:28 |