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

ble_gatts_service_add error code 0x0000000c

Hello, I am trying to set my own BLE service, and on the adverstisement initialization I get an error 0x0000000c when calling to ble_advertising_init().

Why does it mean and happen? How can I fix it?

Thanks in advance

My uuids are initialized like this

#define SERVICE_UUID_BASE {0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0x00, 0x00, 0xAB, 0xAB}
#define D_SERVICE_UUID 0xE800
#define D_42_CHAR_UUID 0xE801
#define D_DT_CHAR_UUID 0xE802
#define D_GO_CHAR_UUID 0xE803
#define D_LG_CHAR_UUID 0xE804


static ble_uuid128_t D_base_uuid = SERVICE_UUID_BASE ;
static ble_uuid_t m_adv_uuids[] = {{D_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN },
                                         {BLE_UUID_BATTERY_SERVICE, BLE_UUID_TYPE_BLE},
                                         {BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}
                                       };

My adverstising method looks like

static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advdata_t          advdata;
    ble_adv_modes_config_t options;

    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = m_adv_uuids;

    memset(&options, 0, sizeof(options));
    options.ble_adv_fast_enabled  = true;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

    err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
}

Finally part of my service initialization is

    uint32_t ble_D_init(ble_D_t * p_D, const ble_D_init_t * p_D_init)
    {
        uint32_t   err_code;
        ble_uuid_t ble_uuid;
        ble_uuid128_t base_uuid = D_base_uuid;
    
    
        // Initialize service structure
        p_D->evt_handler                 = p_D_init->evt_handler;
        p_D->is_sensor_contact_supported = p_D_init->is_sensor_contact_supported;
        p_D->conn_handle                 = BLE_CONN_HANDLE_INVALID;
        p_D->is_sensor_contact_DTected  = false;
        p_D->interval_count              = 0;
        p_D->max_D_len              = INIT_MAX_LEN;
    
    
        // Add service
        err_code = sd_ble_uuid_vs_add(&base_uuid, &(p_D->uuid_type));
        APP_ERROR_CHECK(err_code);// HERE err_code = 0x00000000
    
        ble_uuid.type = p_D->uuid_type;
        ble_uuid.uuid = D_SERVICE_UUID;

        err_code =sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,&ble_uuid,&p_D->service_handle);//HERE err_code = 0x00000000
...}
  • If you just single-stepped into the function you'd find very quickly where the error is coming from. My guess would be

    #define NRF_ERROR_DATA_SIZE     (NRF_ERROR_BASE_NUM + 12) ///< Invalid Data size
    

    ie you're trying to encode more data than fits in the packet probably because you have added long UUIDS to short UUIDS and there's never enough space for that.

    And i just noticed .. BLE_UUID_TYPE_VENDOR_BEGIN. Do not use this. I really don't know where this incorrect practice came from. You register the UUID base you want, but then you need to use the identifier returned (which may well be equal to BLE_UUID_TYPE_VENDOR_BEGIN and may not). You can't assume equal too the vendor start.

    ps your title is rather misleading as you say the error comes from the advertising init function and not the service add one.

    pps if you'd typed 'ble_advertising_init 12' into the search box at the top you'd have found 20 answers to this.

  • Add the vendor specific UUID in the scan response packet instead. See the ble_app_uart example on how this is done there.

Related