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

Advertising custom service uuid

Hi community,

I custom a service and need it be filter by mobile phone. For that I need my service uuid show up in advertisement.

Search some article. And find SDK example ble_app_uart could do what I want.

Use the example it work perfectly. But I try to do same in my project it dosen't work.

I try to do like the example:

#define MY_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN
static ble_uuid_t m_adv_uuids[] = {{MY_SERV_UUID, MY_UUID_TYPE}};

Before I try to advertising custom uuid my custom service is work great. When I try to make it advertising custom uuid it crash and get the error.

APP_ERROR:ERROR:Fatal

Is I missed something need to be done?

  • Don't use BLE_UUID_TYPE_VENDOR_BEGIN, register the UUID you need with sd_ble_uuid_vs_add() and use the return from that function as MY_UUID_TYPE

    I don't know where the practice of trying to use that constant came from, it's always been wrong.

  • I follow "/examples/ble_peripheral/ble_app_uart"

    add in advertising_init()

    ble_advdata_t          scanrsp;
    ...
    memset(&scanrsp, 0, sizeof(scanrsp));
    scanrsp.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    ...
    scanrsp.uuids_complete.p_uuids  = m_adv_uuids;
    ...
    err_code = ble_advertising_init(&advdata, &scanrsp, &options, on_adv_evt, NULL);
    

    Problem solved! I could do what I want advertising custom 128 uuid and let mobile can filter it.

    Not sure it's good way but it work for me.

Related