This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Cannot connect to peripheral using custom vendor service (nAN-36)

Hi, after reading the nAN-36, I tried to write an application for the nRF51822, with the custom Led Service provided with nAN-36.

I take as a base the Nordic HRM application (s110/ble_app_hrs), I removed the HR related service, variables etc. and inserted the code for the Led Service (as provided in nAN-36 ble_lbs).

With some adjustments, I've managed to make it run.

One first problem was that if I set the advertising data like this:


ble_uuid_t adv_uuids[] =
{
    {LBS_UUID_SERVICE, m_lbs.uuid_type},
    {BLE_UUID_BATTERY_SERVICE,            BLE_UUID_TYPE_BLE},
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
};

// Build and set advertising data.
memset(&advdata, 0, sizeof(advdata));

advdata.name_type               = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance      = true;
advdata.flags.size              = sizeof(flags);
advdata.flags.p_data            = &flags;
advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
advdata.uuids_complete.p_uuids  = adv_uuids;

err_code = ble_advdata_set(&advdata, NULL);
APP_ERROR_CHECK(err_code);

I get a 0x0C error when I call the: ble_advdata_set(&advdata, NULL);

So I've used the scan response data and set the advertising data this way:


ble_uuid_t adv_uuids[] =
{
    {BLE_UUID_BATTERY_SERVICE,            BLE_UUID_TYPE_BLE},
    {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
};

ble_uuid_t mra_uuids[] =
{
    {LBS_UUID_SERVICE, m_lbs.uuid_type}
};

advdata.name_type               = BLE_ADVDATA_FULL_NAME;
advdata.include_appearance      = true;
advdata.flags.size              = sizeof(flags);
advdata.flags.p_data            = &flags;
advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
advdata.uuids_complete.p_uuids  = adv_uuids;

memset(&scanrsp, 0, sizeof(scanrsp));
scanrsp.uuids_complete.uuid_cnt = sizeof(mra_uuids) / sizeof(mra_uuids[0]);
scanrsp.uuids_complete.p_uuids  = mra_uuids;
    
err_code = ble_advdata_set(&advdata, &scanrsp);
APP_ERROR_CHECK(err_code);

With this configuration, I can see the advertising packets (with full UUID for the Led Service) on my BLE Central (iPad), but I'm not able to connect to the Peripheral.

Currently advertising flags are set this way:


flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

and


m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
m_adv_params.p_peer_addr = NULL;                           // Undirected advertisement.
m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
m_adv_params.interval    = APP_ADV_INTERVAL;
m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;

Is this a problem with the iOS Bluetooth implementation or are there any other parameters to configure to make the device connectable?

Notice that if I remove the Led Service from the code, I can connect to the Peripheral Device that shows the Battery and the Device Services.

Thanks again for any help/suggestions.

Regards, Samuele.

Parents
  • I was also bitten by this "feature". Since it's no longer obvious how to clear the cache in OSX, the steps are:

    sudo defaults write /Library/Preferences/com.apple.Bluetooth CoreBluetoothCache -dict
    sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
    sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist
    

    Also be warned if you are using the ble_app_hrs example to create your own custom UUIDs you need to make sure you call services_init() before advertising_init() in the main function. Otherwise your custom UUID is not yet initialised.

Reply
  • I was also bitten by this "feature". Since it's no longer obvious how to clear the cache in OSX, the steps are:

    sudo defaults write /Library/Preferences/com.apple.Bluetooth CoreBluetoothCache -dict
    sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
    sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist
    

    Also be warned if you are using the ble_app_hrs example to create your own custom UUIDs you need to make sure you call services_init() before advertising_init() in the main function. Otherwise your custom UUID is not yet initialised.

Children
No Data
Related