Categories

RoseOnRails – BlueZ

During this week I’m in Warsaw lot of activities were mandatory after the courses and during the week-end. I didn’t have a lot of time to work on our project.

But, I’ve tried to do a few things. First, I’ve flashed the program ble_app_proximity (provided as example in nRF51822 SDK). I was in charge of doing part of the software architecture of our project. But, others problematic related to the use of BLE occurred.

First we had to be sure that we don’t need any other microprocessor, in case the SoftDevice couldn’t support the use of an OS. It seems that the question has already been answered by Valeh. For my part I’ve looked how to use a stack BLE on Linux for our station central. I looked all around internet on Wednesday and it appears that BlueZ is probably the only one I found which is suitable but it is poorly documented and most of the code isn’t commented. BlueZ documentation

BlueZ isn’t specific for BLE so we’re going to use the library made by Paluche https://github.com/Paluche/BlueLib. I’ll look through it very soon, it seems that we will have to implement the multi-slaves mode.

I’ve found some useful commands on stack overflow which could be used by others

$ hciconfig
Output :
hci0: Type: BR/EDR Bus: USB
BD Address: 00:01:02:aa:bb:cc ACL MTU: 1021:8 SCO MTU: 64:1
DOWN
RX bytes:1000 acl:0 sco:0 events:47 errors:0
TX bytes:1072 acl:0 sco:0 commands:47 errors:0

//put the device in an up state
$ sudo hciconfig hci0 up
//configure the advertising data
$ sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10
// activate the advertising on the dongle
$ sudo hciconfig hci0 leadv O
//the above command makes the advertised service connectable. If you don’t want to allow connections, change it to :
$ sudo hciconfig hci0 leadv 3
// disable advertising
$ sudo hciconfig hci0 noleadv

Sample commands :
hcitool lescan
hcitool lecc
gatttool -b <Mac Address> –primary
gatttool -b <MAC Address> –characteristics
gatttool -b <MAC Address> –char-read
gatttool -b <MAC Address> –char-desc
gatttool -b <MAC Address> –interactive
gatttool -b <MAC Address> –listen
Sample functions :
gatt_service_add(adapter, GATT_PRIM_SVC_UUID, 0xFFFF,
/* Char 1 */
GATT_OPT_CHR_UUID16, 0xAAAA,
GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ,
GATT_OPT_CHR_VALUE_CB, ATTRIB_READ, read_func_callback,

/* Char 2 Define here */

/* Char 3 Define here */

GATT_OPT_INVALID);
}”
BlueZ
http://www.bluez.org/bluez-low-energy-support-status/

 

5 comments to RoseOnRails – BlueZ

  • allegrem

    And does it work? For example, did you manage to display the characteristic list with the ble_app_proximity example? If yes, I can make an interesting offer for more details 😉

  • yann

    I wasn’t clear about it but I’m still working on it. I didn’t have much time to work and I won’t have a lot until Monday. And I think I’ll have a lot of work on Monday to make it works. Sorry

  • Hubert

    For gatttool, the interactive mode exist (gatttool -I) much easier than one line at the time.
    Disclaimer about BlueLib, the library uses BlueZ, it offers you a simpler interface. Also BlueLib includes things (details but tricky one) from the Bluetooth V4.0 not done by BlueZ.
    The understanding of the BlueLib code, will give you a example on how to use BlueZ.

    If you develop the multi-slave (before me) please think about a pull request 😉

    And about useful command: you’ll probably use the security levels and each time you’ll flash the BLE server you’ll need to erase the configuration in your computer about this device. For this: sudo bluez-simple-agent hci0 repair (hci0 or your actual device you’re using (list with “hcitool dev”))

    And I don’t know if its going to be useful but my initialization sequence for configuring the BLE key in master mode qis the following:
    sudo rfkill unblock `rfkill list | grep hci | sed -e “s/^\([0-9]*\): .*/\1/”`
    sudo hciconfig hci0 up
    sudo hciconfig hci0 lm MASTER
    sudo hciconfig secmgr
    sudo hcitool cmd 0x3 0x6d 0x1 0x0

    If you wonder what it does “man” is your best friend.

  • yann

    Hello Hubert, I had seen that your library was based on BlueZ.
    Thanx for the advice. I keep you posted and will do a pull request if we implement the multi-slave mode.