You Are Here:

Community: Developer Discussion Boards

#1 Old MAC address & device's services - 2007-02-14, 18:22

Join Date: Feb 2007
Posts: 10
jon83
Offline
Registered User
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
Reply With Quote

#2 Old Re: MAC address & device's services - 2007-02-14, 19:37

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
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.
Reply With Quote

#3 Old Re: MAC address & device's services - 2007-02-14, 19:40

Join Date: Oct 2006
Posts: 24
andersnc
Offline
Registered User
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)
More information can be found in section 8.2.2 of the PyS60 documentation (available here, among other places: http://www.mobilenin.com/pys60/resou...doc_1_3_14.pdf).

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.
Reply With Quote

#4 Old Re: MAC address & device's services - 2007-02-15, 10:50

Join Date: Feb 2007
Posts: 10
jon83
Offline
Registered User
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?
Reply With Quote

#5 Old Re: MAC address & device's services - 2007-02-15, 11:09

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Like I said, there seems to be no way to get the class of a Bluetooth device from within PyS60. Sorry!
Reply With Quote

#6 Old Re: MAC address & device's services - 2007-02-15, 14:03

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
Quote:
Originally Posted by jethro.fn
Like I said, there seems to be no way to get the class of a Bluetooth device from within PyS60. Sorry!
No jethro ! It seems that you can get class of bluetooth device within PyS60 with lightblue library

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/
Reply With Quote

#7 Old Re: MAC address & device's services - 2007-02-15, 14:46

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by cyke64
No jethro ! It seems that you can get class of bluetooth device within PyS60 with lightblue library
Nice! No version for 3rd Edition yet, though.
Reply With Quote

#8 Old Re: MAC address & device's services - 2007-02-16, 13:32

Join Date: Feb 2007
Posts: 10
jon83
Offline
Registered User
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.
Reply With Quote

#9 Old Re: MAC address & device's services - 2007-02-18, 00:02

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by jon83
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.
There's also a finddevices() function:

Quote:
finddevices(getnames=True, length=10)
Performs a device discovery and returns the found devices as a list of
(address, name, class-of-device) tuples. Raises BluetoothError if an error
occurs.
It gives you the class of each device. Then you can use splitclass(classofdevice) to get the major and minor class numbers. Those tell you whether the device is a PC, a phone or something else.
Reply With Quote

#10 Old Re: MAC address & device's services - 2007-02-19, 15:27

Join Date: Feb 2007
Posts: 10
jon83
Offline
Registered User
Quote:
Originally Posted by jethro.fn
There's also a finddevices() function:



It gives you the class of each device. Then you can use splitclass(classofdevice) to get the major and minor class numbers. Those tell you whether the device is a PC, a phone or something else.

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
Reply With Quote

#11 Old Re: MAC address & device's services - 2007-02-19, 16:00

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
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
Reply With Quote

#12 Old Re: MAC address & device's services - 2007-02-19, 16:17

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
Quote:
Originally Posted by jethro.fn
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
Jethro.fn , this link has already posted here (last year !)

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

#13 Old Re: MAC address & device's services - 2007-02-19, 16:23

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by cyke64
Jethro.fn , this link has already posted here (last year !)
Right. Well, no harm in repeating it...
Reply With Quote

#14 Old Re: MAC address & device's services - 2007-02-22, 17:13

Join Date: Feb 2007
Posts: 10
jon83
Offline
Registered User
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()
Reply With Quote

#15 Old Re: MAC address & device's services - 2007-02-22, 20:42

Join Date: Feb 2007
Posts: 10
jon83
Offline
Registered User
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 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
Similar Threads
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

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