×

Discussion Board

Results 1 to 5 of 5

Hybrid View

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    2

    Problem with service attribute propagation and service attribute retrieval

    Hi all,

    I've got a problem in service with service attribte propagation and service attribute retrieval. I want to implement a service that propagates additional information about the service by using an individual service attribute.
    The prppagation of the service attribute should work. I'm using the code below:

    try{
    //connection string: scheme, target, parameters
    //... for servers: btspp://localhost:serviceuuid;name=servicename
    //... for clients: btspp://00803dad2AA1:3;authenticate=true
    UUID uuid = new UUID(0x0003);
    notifier = (StreamConnectionNotifier)Connector.open("btspp://localhost:"+uuid.toString()+";name=Scatternet");

    //modify the service record here
    LocalDevice ld = LocalDevice.getLocalDevice();
    ServiceRecord sr = ld.getRecord(notifier);

    analyseServiceRecord(sr);

    long seqno = 0;
    //Construct a new seqno DataElement
    DataElement seqnoDataElement = new DataElement(DataElement.U_INT_4, seqno);
    //Write the new seqno DataElement
    boolean successful = sr.setAttributeValue(ATTRIBUTE_ID, seqnoDataElement);
    System.out.println("ReceiveManager: ServiceRecord modified successfully: " + successful);

    analyseServiceRecord(sr);

    //Explicitely update the ServiceRecord in the SDDB of the LocalDevice, otherwise no effect will take place.
    ld.updateRecord(sr);

    analyseServiceRecord(sr);

    System.out.println("ServiceRecord modified. Current SeqNo = " + seqno);
    } catch (BluetoothStateException bse){
    bse.printStackTrace();
    } catch (ServiceRegistrationException sre){
    sre.printStackTrace();
    } catch (IOException ioe){
    ioe.printStackTrace();
    }

    The <code>analyseServiceRecord(sr)</code> statements produce the following output, indicating that the ServiceRecord sr has been modified:

    AttribID: 256 DataType: STRING DataValue: Scatternet

    AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@1a4cfaaa, javax.bluetooth.DataElement@1cb37664,

    AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@f828ed68,

    AttribID: 0 DataType: INT_4 DataValue: 0

    ReceiveManager: ServiceRecord modified successfully: true

    AttribID: 256 DataType: STRING DataValue: Scatternet

    AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@ea0ef881, javax.bluetooth.DataElement@84aee8b,

    AttribID: 11 DataType: U_INT_4 DataValue: 0

    AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@c5c7331,

    AttribID: 0 DataType: INT_4 DataValue: 0

    AttribID: 256 DataType: STRING DataValue: Scatternet

    AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@e938beb1, javax.bluetooth.DataElement@11eaa96,

    AttribID: 11 DataType: U_INT_4 DataValue: 0

    AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@15549f7c,

    AttribID: 0 DataType: INT_4 DataValue: 0

    ServiceRecord modified. Current SeqNo = 0


    The following code shows how I'm trying to read the service record attribute (usually via another device):

    int [] attrSet = {ATTRIBUTE_ID};
    try{

    boolean successful = servRecord[i].populateRecord(attrSet);
    System.out.println("Explicitely retrieving SeqNo service attribute: " + successful);
    } catch (IOException ioe){
    System.out.println("servRecord[i].populateRecord(attrSet) FAILED");
    ioe.printStackTrace();
    }
    ReceiveManager.analyseServiceRecord(servRecord[i]);
    //
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);

    try{
    dos.writeUTF(servRecord[i].getHostDevice().getBluetoothAddress());
    String friendlyName;
    try{
    friendlyName = servRecord[i].getHostDevice().getFriendlyName(true);
    } catch (IOException ioe){
    friendlyName = servRecord[i].getHostDevice().getFriendlyName(false);
    }
    dos.writeUTF(friendlyName);//friendlyName

    dos.writeInt(1);
    // dos.writeLong(1);//seqno

    //Get the current Attribute of the RemoteDevice from its ServiceRecord
    ServiceRecord sr = servRecord[i];
    //Read the seqno DataElement
    int [] attrIDs = {ATTRIBUTE_ID_ID};
    boolean successful = sr.populateRecord(attrIDs);
    System.out.println("PiconetManager: Retrieving SeqNo from ServiceRecord successfully: " + successful);
    if(successful){
    DataElement seqnoDataElement = sr.getAttributeValue(ATTRIBUTE_ID);
    long seqno = seqnoDataElement.getLong();
    dos.writeLong(seqno);//seqno
    } else {
    System.out.println("PiconetManager: Could not retrieve SeqNo from ServiceRecord. (Line 103)");
    return;
    }

    } catch (IOException ioe){

    ioe.printStackTrace();
    }




    That produces the following output:



    Searching on device No. 1 of 1 for a RFCOMM service with ATTRIBUTE_ID in its attribute set.

    Service discovered

    Explicitely retrieving Attribute service attribute: false

    AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@f3c47ffc, javax.bluetooth.DataElement@96d5985,

    AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@1653d53f,

    AttribID: 0 DataType: INT_4 DataValue: 0

    Retrieving SeqNo from ServiceRecord successfully: false

    Could not retrieve SeqNo from ServiceRecord. (Line 103)

    Service search completed


    QUESTION: Can anybody tell me why I can't retrieve the attribute?

    Thanks.

    Patrick

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    12
    no, cant tell you whats wrong, infact im having the same problem, I can supposedly set these service record attributes as you say, and its says they are set i.e. no errors been thrown, but when I try it on the Nokia 6600, it just has the original service record attributes only.

    I tried seeting for both my own services and those exisiting services and both failed. On the phone itself it also tells me its sets them , but when i try to retrieve the service record from the second phone they are not present (and yes I have them in my attr list)

    Anyone could help, it would be good, what about that Graham guy, he seems to know everything about J2ME??
    Graham are you there? Whats the solution?

    Regards,
    Issey

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    12
    i got it working with a custom service using a long form of UUID in my notifier eg 1020304050D0708093A1B121D1E1F100 on a Nokia 6600, couldnt get it to work with short form of UUID for existing services or short form of UUID using custom services, im pretty new at this so guess i dont know how to do my connections correctly and neither do those idiots who write those Bluetooth books.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    8
    I'm having this problem too in C++. Have you guys seen this thread ?

    Developer Discussion Boards > > Connectivity > Bluetooth Technology > Calculating with base value to get offset for service ID

    I seem to remember the docs talking about adding some base bluetooth address to your id's - perhaps that's it..

    CW

  5. #5
    Registered User
    Join Date
    Mar 2003
    Location
    Egypt
    Posts
    48

    Lightbulb Re: Problem with service attribute propagation and service attribute retrieval

    Do you mean to publish something like a string about ur server? Try to use attribitute 51. I used it before successfully to publish more date about my server. But actualy I dnt remember why.

Posting Permissions

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