Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 28
Registered: ‎06-10-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: None
Accepted Solution

Setting up bluetooth low energy callback

Im having problems trying to adapt the Cascades "BluetootoothSPPChat example(on Blackberry gitHub). to scan for bluetooth low energy devices. My current road block in trying to adopt instructions from JAM 21 session code descriptions to the Cascade example is the following:

bt_le_callbacks_t le_callbacks = {
   .advert = le_advertisement_cb

But the compiler is complaining about syntax so I split in up to the following:

bt_le_callbacks_t le_callbacks;

le_callbacks.advert = le_advertisement_cb;

But the compiler is complaining about mismatching return types.


I have the imports:
#include <btapi/btdevice.h>
#include <btapi/btle.h>


and a skeletal function definition for le_advertisement_cb:


void le_advertisement_cb(const char *bdaddr, const char *data, int len, void *userData){



Any help would be much appreciated.



Posts: 32
Registered: ‎08-26-2008
My Device: Not Specified

Re: Setting up bluetooth low energy callback

Hi rbork,


I am also working with BT LE, and I think I passed this roadblock. Try this:


#include <QDebug>
#include <btapi/btdevice.h>
#include <btapi/btgatt.h>
#include <btapi/btle.h>
#include <errno.h>

void my_advertisement_cb (const char *bdaddr, int8_t rssi, const char *data, int len, void *userData) { qDebug("Advertisement from BTAddr:%s. (Signal strength %d)", bdaddr, rssi); } /* * Note that this must be static. `bt_le_init()` does not "retain" the callbacks. */ static bt_le_callbacks_t le_callbacks = { my_advertisement_cb }; void initAndSearch() { bt_le_init(&le_callbacks); qDebug("BEGIN Scanning for device!"); int retVal = bt_le_add_scan_device(BT_LE_BDADDR_ANY, this); if (retVal != EOK) { qDebug("Couldn't start scanning for devices. Error: %d", retVal); } }

 I am stuck at getting a service to connect. I'll start a new thread for that challenge Smiley Happy

Good luck!