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

Advertise two services?

How can I advertise a custom service and the Device Information Service?

I tried the following, but only my custom service is visible in the Nordic Master Control panel app on iOS. With our own iPhone app, we can also only find the custom service although trying to discover the device information service as well.

static ble_uuid_t m_uuids_advertising[] = { {
        BLE_SERVICE_UUID_SERVICE_LIGHT,
        BLE_UUID_TYPE_VENDOR_BEGIN
    }
};



static ble_uuid_t m_uuids_scan_response[] = { {
        BLE_UUID_DEVICE_INFORMATION_SERVICE,
        BLE_UUID_TYPE_BLE
    }
};

/// ....

	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_uuids_advertising)
			/ sizeof(m_uuids_advertising[0]);
	advdata.uuids_complete.p_uuids = m_uuids_advertising;

	ble_adv_modes_config_t options = { 0 };
	// TODO: What does that whitelist do?
	options.ble_adv_whitelist_enabled = BLE_ADV_WHITELIST_ENABLED;
	options.ble_adv_fast_enabled = BLE_ADV_FAST_ENABLED;
	options.ble_adv_fast_interval = APP_ADV_FAST_INTERVAL;
	options.ble_adv_fast_timeout = APP_ADV_FAST_TIMEOUT;

	options.ble_adv_slow_enabled = BLE_ADV_SLOW_ENABLED;
	options.ble_adv_slow_interval = APP_ADV_SLOW_INTERVAL;
	options.ble_adv_slow_timeout = APP_ADV_SLOW_TIMEOUT;

    srdata.uuids_more_available.uuid_cnt = sizeof(m_uuids_scan_response) / sizeof(m_uuids_scan_response[0]);
    srdata.uuids_complete.p_uuids = m_uuids_scan_response;

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

I also did set up the Device Information Service itself in services_init:

// Initialize Device Information Service.
    ble_dis_init_t dis_init;
    ble_dis_sys_id_t sys_id;
    memset(&dis_init, 0, sizeof(dis_init));
    ble_srv_ascii_to_utf8(&dis_init.manufact_name_str, MANUFACTURER_NAME);
    ble_srv_ascii_to_utf8(&dis_init.model_num_str,     MODEL_NUM);
    // ...

    sys_id.manufacturer_id            = MANUFACTURER_ID;
    sys_id.organizationally_unique_id = ORG_UNIQUE_ID;
    dis_init.p_sys_id                 = &sys_id;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&dis_init.dis_attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&dis_init.dis_attr_md.write_perm);
    err_code = ble_dis_init(&dis_init);
    APP_ERROR_CHECK(err_code);
Parents
  • srdata.uuids_more_available.uuid_cnt = sizeof(m_uuids_scan_response) / sizeof(m_uuids_scan_response[0]);
    srdata.uuids_complete.p_uuids = m_uuids_scan_response;
    

    you're setting the uuids_complete.p_uuids in the scan response so you need to set the uuids_complete.uuid_cnt not the uuids_more_available.uuid_cnt. Surprised the encoder doesn't barf on that as the pointer it's deferencing is invalid.

    Don't use BLE_UUID_TYPE_VENDOR_BEGIN either, use the handle you got back when you registered your custom UUID.

Reply
  • srdata.uuids_more_available.uuid_cnt = sizeof(m_uuids_scan_response) / sizeof(m_uuids_scan_response[0]);
    srdata.uuids_complete.p_uuids = m_uuids_scan_response;
    

    you're setting the uuids_complete.p_uuids in the scan response so you need to set the uuids_complete.uuid_cnt not the uuids_more_available.uuid_cnt. Surprised the encoder doesn't barf on that as the pointer it's deferencing is invalid.

    Don't use BLE_UUID_TYPE_VENDOR_BEGIN either, use the handle you got back when you registered your custom UUID.

Children
No Data
Related