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

Advertising BLE FOTA service and custom service with Zephyr

I am having problems advertising both FOTA and a custom service.  I started with the peripheral sample (zephyr\samples\bluetooth\peripheral) and the smp_svr sample (\zephyr\samples\subsys\mgmt\mcumgr\smp_svr)

In the peripheral sample, the advertising data is this:

static const struct bt_data ad[] = {
  BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
  BT_DATA_BYTES(BT_DATA_UUID16_ALL,
    BT_UUID_16_ENCODE(BT_UUID_HRS_VAL),
    BT_UUID_16_ENCODE(BT_UUID_BAS_VAL),
    BT_UUID_16_ENCODE(BT_UUID_CTS_VAL)),
  BT_DATA_BYTES(BT_DATA_UUID128_ALL,
    0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12,
    0x78, 0x56, 0x34, 0x12, 0x78, 0x56, 0x34, 0x12),
};

In the smp_svr sample, the advertising data for the FOTA service is this:

static const struct bt_data ad[] = {
  BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
  BT_DATA_BYTES(BT_DATA_UUID128_ALL,
    0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86,
    0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
};

In both samples, this array is passed into the bt_le_adv_start function, although the smp_svr calls the advertising function through the work queue (struct k_work).

My question is, how do I advertise both services?  I was not able to find any documentation on the format of the ad[] array

  • Hi,

    Did you check the return value from bt_le_adv_start()? I would expect it was -EINVAL, as the advertising packet will be too big in this case. So you either need to put e.g. the 128 bit UUID in the scan response packet instead, or decide not to advertise all the UUIDs (there is typically no need to advertise all service UUIDs).

  • Hello Einar,

    Yes, exactly, the response was -EINVAL when putting both 128 bit UUIDs in the advertising array.  If you say there is no need to advertise all UUIDs then maybe I am looking at the wrong place for a solution.

    (Edited) This is my actual problem after some digging:

    When I run my Android test app (which uses the Nordic BLE SDK), on my Android 9 device there is no issue, but on my Android 7 device, the app fails to retrieve the custom service that is not advertised.  It seems that the service discovery is not working

    I ran nrfConnect on the Android 7 device and I noticed it also had issues with not being able to discover services on my devices.

    Same APK, different result. These devices are commercial OEM tablets.  Perhaps there is something wrong with the Android implementation?

  • Hi,

    Based on what you write this seems to be an issue on the Android side, so you should look more into that. You should always be able to discover all services when doing service discovery.

Related