How to assign service UUID and how to retrieve it

Ask, and ye shall receive.
zardaloop
Posts: 3
Joined: 07:51, 08 Sep 2014

How to assign service UUID and how to retrieve it

Postby zardaloop » 07:56, 08 Sep 2014

Hi guys,

I am having a little bit of issue and I was wondering if someone could please help me with that.

I currently know the uuid of the device that I want to connect to and I get connected to it fine. However what I want to do is being able to receive data from the is sent to my mobile phone from the RFDuino.

I am not entirely sure what are the characteristics and how to get services etc. :? I would highly appreciate if you could please take a look at my code and let me know what I am doing wrong here ? Please see my codes below. for the phone gap part I have only copied the relevant methods. :ugeek: :geek:

Many thanks in advance.
Farzan


This is what I have in the phone gap side :

Code: Select all

function connectToBLE(){

    // $scope.bleDevice['address'] give me the correct map
    evothings.ble.connect($scope.bleDevice['address'],
        function(connectInfo){
   //I am getting connected correctly
        $scope.result = connectInfo.toString();   
            deviceHandle = connectInfo.deviceHandle;
            getServices(deviceHandle);
             startReadingBLE();
        }
       ,function(err){

        $scope.result = err;

    });
}

function getServices(deviceHandle){
// gets here but failes to run this method, any idea ?
        evothings.ble.services(deviceHandle, function(service)
        {
          alert(service.service.uuid);
          var characteristic = service.characteristics[ci];
            for (var si in services)
                {
                    var service = services[si];

                    for (var ci in service.characteristics)
                    {
                        if (characteristic.uuid == $scope.bleDevice['address'])
                        {
                            characteristicRead = characteristic.handle;
                            startReadingBLE();

                        }
                    }
                }
        },
        function(errorCode)
        {
            $scope.result='Service error: ' + errorCode;
        });
}


function stopReadingBLE(){
    try{
        evothings.ble.disableNotification(
    deviceHandle,
    characteristic.handle,
    function()
    {
    },
    function(errorCode)
    {
    });

    }catch(err){
        $scope.result = err;
    }
   

}

function startReadingBLE(){
    evothings.ble.enableNotification(
    deviceHandle,
    characteristicRead,
    onSuccess,
    function(errorCode)
    {
        $scope.result ="BLE enableNotification error:" + errorCode;
    });
}


And this is what I have in the RFduino :

Code: Select all

#include <RFduinoBLE.h>

bool isconnected = false;

void setup() {
  // setup the leds for output
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT); 
  pinMode(led3, OUTPUT);

  RFduinoBLE.advertisementData = “Test";
  RFduinoBLE.deviceName ="Amigo";
 
  // start the BLE stack
  RFduinoBLE.begin();
}

void loop() {
  // switch to lower power mode
  RFduino_ULPDelay(INFINITE);
  if (isconnected){
  delay(3000);
  RFduinoBLE.send('hello');
  } 
}

void RFduinoBLE_onConnect() {
  isconnected = true;
}

void RFduinoBLE_onDisconnect() {
}

void RFduinoBLE_onReceive(char *data, int len) { 
}
Last edited by zardaloop on 13:57, 08 Sep 2014, edited 1 time in total.

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: How to assign service UUID and how to retrieve it

Postby ardiri » 13:42, 08 Sep 2014

it would be great if you could use the code tags - makes your post easier to read.

for the RFduino - you can set a custom UUID; thats easy, here is an example for the rfduino side of things - you also detect the device using the deviceName - which you can also set as well.

Code: Select all

  // configure the device and set a custom UUID
  RFduinoBLE.deviceName = "carcontrol";
  RFduinoBLE.customUUID = "12340000-cbed-76db-9423-74ce6ab53dee";
  RFduinoBLE.begin();


for the RFduino; there are separate UUID's for reading and writing - unfortunately they are not the same in the manner in which they work as compared to the redbear labs BLE shields.

Code: Select all

app.ID_SERVICE =
  [
    '713d0000-503e-4c75-ba94-3148f18d941e',  // RedBearLabs - BLE Shield
    '713d0000-503e-4c75-ba94-3148f18d941e',  // RedBearLabs - Blend Micro
    '12340000-cbed-76db-9423-74ce6ab53dee',  // RFDuino
    'a495ff20-c5b1-4b44-b512-1370f02d74de'   // lightblue bean
  ];
app.ID_CHARACT =
  [
    '713d0003-503e-4c75-ba94-3148f18d941e',  // RedBearLabs - BLE Shield
    '713d0003-503e-4c75-ba94-3148f18d941e',  // RedBearLabs - Blend Micro
    '12340002-cbed-76db-9423-74ce6ab53dee',  // RFDuino
    'a495ff21-c5b1-4b44-b512-1370f02d74de'   // lightblue bean
  ];


you can see the RX UUID on the redbear labs is actually +3 from the UUID (first dword) where the RFduino is +2 - for TX i believe it is +2 and +1 respectively - i posted about this on the http://forum.rfduino.com/index.php?topic=785.0 (rfduino forums), but that may help you understand the relationship between the device UUID and the UUID of the characteristics.. i haven't released the update to our BLE RC buggy example yet (some of the code is above) but it will highlight that there are difference UUID and UUID service characteristics depending on the device in use.

part 1: http://evothings.com/evothings-hacknight-part1/
part 2: http://evothings.com/evothings-hacknight-part2/
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/

zardaloop
Posts: 3
Joined: 07:51, 08 Sep 2014

Re: How to assign service UUID and how to retrieve it

Postby zardaloop » 16:56, 08 Sep 2014

Many Thanks Ardiri,
I have added the code tag so hopefully it is making it easier to read.
Thanks a lot for the great explanation of the Services and characteristics. So let me get this right. so if for example my UUID in RFduino is :

Code: Select all

RFduinoBLE.customUUID = "12340000-cbed-76db-9423-74ce6ab53dee";


then the reading characteristic or RX characteristic UUID will be :

Code: Select all

RX_UUID = "12340000-cbed-76db-9423-74ce6ab53dee"+2;


and the Writing or TX characteristic UUID will be :

Code: Select all

TX_UUID ="12340000-cbed-76db-9423-74ce6ab53dee"+1;


And then in the nodejs side to get readings for example I use

Code: Select all

evothings.ble.enableNotification(
    deviceHandle,
    RX_UUID,
    onSuccess,
    function(errorCode)
    {
        $scope.result ="BLE enableNotification error:" + errorCode;
    });


Am I understanding you correct? :ugeek:

Where do these UUID come from ? are they set by the manufacturer? or I should use Arduino application to write them to RFduino? where is the actual documentation for these? :shock: :? :?: :?: :?:

Once again many thanks for your help.

Cheers,
Farzan

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: How to assign service UUID and how to retrieve it

Postby micke » 19:43, 08 Sep 2014

Hi Farzan,

Yes, it is the manufacturer that sets the UUIDs for services and characteristics, and they are not always well documented :? :roll: :!:

Here is a small example that scans for devices and connects to a named device (you have to enter the name in the JavaScript code in index.html), then prints services, characteristics and descriptors. There is also some instructions in the README file:

https://github.com/divineprog/evo-demos ... LEExplorer

Cheers!

Mikael

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: How to assign service UUID and how to retrieve it

Postby ardiri » 21:39, 08 Sep 2014

no, you have mis-understood. when:

Code: Select all

12340000-cbed-76db-9423-74ce6ab53dee


is the UUID of the service, then - then the characteristics are:

Code: Select all

12340001-cbed-76db-9423-74ce6ab53dee - write
12340002-cbed-76db-9423-74ce6ab53dee - read


the +1 and +2 happen on the first DWORD of the UUID. for the RFDuino you can set whatever UUID you like - the post i made on the RFduino forum was to complain that the mapping between service UUID and characteristic UUID are not consistent; this is because redbear labs have an additional service for "device information" which the RFduino doesn't - it was only after playing with a few different devices that it was obvious there was no standard for UUID mappings between service and characteristics.
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/

zardaloop
Posts: 3
Joined: 07:51, 08 Sep 2014

Re: How to assign service UUID and how to retrieve it

Postby zardaloop » 09:01, 09 Sep 2014

Many thanks Mikael that was a fantastic tutorial and it helped me a lot.

also many thanks Ardiri, yes you are right, I have contacted Chris Paulson who is behind the RFduino project etc and he has mentioned the UUID's that work with the RFduino are as follows.

Code: Select all

UUIDs -
2220 - Base Service UUID
2221 - Receive UUID
2222 - Send UUID
2223 - Disconnect UUID


And as you can guess bang, everything started to work :)

Many thanks guys

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: How to assign service UUID and how to retrieve it

Postby ardiri » 09:37, 09 Sep 2014

zardaloop wrote:also many thanks Ardiri, yes you are right, I have contacted Chris Paulson who is behind the RFduino project etc and he has mentioned the UUID's that work with the RFduino are as follows.

Code: Select all

UUIDs -
2220 - Base Service UUID
2221 - Receive UUID
2222 - Send UUID
2223 - Disconnect UUID


And as you can guess bang, everything started to work :)


those are the default RFduino UUID's - however, you can set a custom UUID and then, the +1 +2 +3 on the DWORD principle applies. i do not believe it is possible to reset the UUID back to 2220 once you have set a custom one either. if you were to set the UUID as i mentioned above, it would also work - but great to see it work with the default UUID's as well. my goal was to make the UUID's consistent across redbear labs and RFduino, but unfortunately, inconsistent designs hampered that effort.
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 2 guests