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

A question about the UUID & Characteristic ID

HI Sir:
 I have meet a strange question using the BLE_UART example.

The code as following:

static ble_uuid_t                       vive_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, BLE_UUID_TYPE_BLE}};  /**< Universally unique service identifier. */

and the advertising_init as following:

static void advertising_init(void)
{
  
  uint32_t   err_code;
  ble_advdata_t advdata;
  ble_advdata_manuf_data_t manuf_specific_data; 
  manuf_specific_data.company_identifier = 0;
  manuf_specific_data.data.p_data = (uint8_t *) sn_number;
     manuf_specific_data.data.size   = 8;
  memset(&advdata, 0, sizeof(advdata));
  advdata.name_type     = BLE_ADVDATA_FULL_NAME;
  advdata.include_appearance = false;
  advdata.flags      = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
  advdata.uuids_complete.uuid_cnt = sizeof(vive_adv_uuids) / sizeof(vive_adv_uuids[0]);
      advdata.uuids_complete.p_uuids  = vive_adv_uuids;
  advdata.p_manuf_specific_data=&manuf_specific_data;
  ble_adv_modes_config_t options = {0};
  options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
  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);
}

And modified the service_init as following :

uint32_t ble_nus_init(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
{
  uint32_t   err_code;
  ble_uuid_t   ble_uuid;
  
  VERIFY_PARAM_NOT_NULL(p_nus);
  VERIFY_PARAM_NOT_NULL(p_nus_init);
 
  // Initialize the service structure.
  p_nus->conn_handle      = BLE_CONN_HANDLE_INVALID;
  p_nus->data_handler      = p_nus_init->data_handler;
  p_nus->is_notification_enabled = false;

  // Add the service.
  BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_SERVICE);
      err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,&ble_uuid,&p_nus->service_handle);
  if (err_code != NRF_SUCCESS)
      {
          return err_code;
      }
  // Add the RX Characteristic.
  err_code = rx_char_add(p_nus, p_nus_init);
  VERIFY_SUCCESS(err_code);
 
  // Add the TX Characteristic.
  err_code = tx_char_add(p_nus, p_nus_init);
  VERIFY_SUCCESS(err_code);
 
  return NRF_SUCCESS;
}

and the TX & RX added function as following :

static uint32_t rx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
{
 
 /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
  ble_gatts_char_md_t char_md;
  ble_gatts_attr_md_t cccd_md;
  ble_gatts_attr_t attr_char_value;
  ble_uuid_t   ble_uuid;
  ble_gatts_attr_md_t attr_md;
  memset(&cccd_md, 0, sizeof(cccd_md));
  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
  cccd_md.vloc = BLE_GATTS_VLOC_STACK;
  memset(&char_md, 0, sizeof(char_md));
  char_md.char_props.notify = 1;
  char_md.p_char_user_desc  = NULL;
  char_md.p_char_pf    = NULL;
  char_md.p_user_desc_md   = NULL;
  char_md.p_cccd_md    = &cccd_md;
  char_md.p_sccd_md    = NULL;
  BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_RX_CHARACTERISTIC);
  memset(&attr_md, 0, sizeof(attr_md));
  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
  BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
  attr_md.vloc     = BLE_GATTS_VLOC_STACK;
  attr_md.rd_auth     = 0;
  attr_md.wr_auth     = 0;
  attr_md.vlen     = 1;
  memset(&attr_char_value, 0, sizeof(attr_char_value));
  attr_char_value.p_uuid   = &ble_uuid;
  attr_char_value.p_attr_md = &attr_md;
  attr_char_value.init_len  = sizeof(uint8_t);
  attr_char_value.init_offs = 0;
  attr_char_value.max_len   = BLE_NUS_MAX_RX_CHAR_LEN;
  return sd_ble_gatts_characteristic_add(p_nus->service_handle,&char_md,&attr_char_value,&p_nus->rx_handles);

}

static uint32_t tx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
{
 ble_gatts_char_md_t char_md;
   ble_gatts_attr_t   attr_char_value;
   ble_uuid_t    ble_uuid;
   ble_gatts_attr_md_t attr_md;
  
   memset(&char_md, 0, sizeof(char_md));
  
   char_md.char_props.write     = 1;
   char_md.char_props.write_wo_resp   = 1;
   char_md.p_char_user_desc     = NULL;
   char_md.p_char_pf       = NULL;
   char_md.p_user_desc_md     = NULL;
   char_md.p_cccd_md       = NULL;
   char_md.p_sccd_md       = NULL;
   BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_TX_CHARACTERISTIC);
  
   memset(&attr_md, 0, sizeof(attr_md));
   BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
   BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
   attr_md.vloc        = BLE_GATTS_VLOC_STACK;
   attr_md.rd_auth       = 0;
   attr_md.wr_auth       = 0;
   attr_md.vlen        = 1;
  
   memset(&attr_char_value, 0, sizeof(attr_char_value));
 
   attr_char_value.p_uuid     = &ble_uuid;
   attr_char_value.p_attr_md     = &attr_md;
   attr_char_value.init_len     = 1;
   attr_char_value.init_offs     = 0;
   attr_char_value.max_len     = BLE_NUS_MAX_TX_CHAR_LEN;
  
   return sd_ble_gatts_characteristic_add(p_nus->service_handle,&char_md,&attr_char_value,&p_nus->tx_handles);

}

The question is very strange ,we using nrfconnect app on iphone and android mobile (MI Note3) to scan the device:

1.The UUID is the same in two mobile phone(using the nrfconnect to test)

 iphone will display 0xFFF0,and android will display the uuid is :

0x0000FFF0-0000-1000-8000-00805F9B34FB.

2.And the RX & TX Characteristic

There is a very strange, the iphone will display the TX &RX Characteristic ID:

 {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0xF6, 0xFF, 0x40, 0x6E}}

But the Android phone display the RX &TX Characteristic ID As following :

0x0000FFF6-0000-1000-8000-00805F9B34FB.

Why ,How can i modify it ?

And how to do to realize only 16bits Id will be dislplay?

Parents
  • HI Lee, 

    Which SDK version are you using? SDK v12.3.0?

    The Nordic UART Service(NUS) is a Vendor Specific Bluetooth Service, not a Bluetooth SIG Service. So you need to make the following changes:

    1. Setting the UUIDs to advertise

    static ble_uuid_t                       vive_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, BLE_UUID_TYPE_BLE}};  /**< Universally unique service identifier. */

    must be changed to 

    static ble_uuid_t vive_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}}; /**< Universally unique service identifier. */

    2. Adding the Vendor Specific UUID

    // Add the service.
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_SERVICE);
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,&ble_uuid,&p_nus->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    

    must be changed to the following

    ble_uuid_t            ble_uuid;
    ble_uuid128_t         nus_base_uuid = NUS_BASE_UUID;
    
    /**@snippet [Adding proprietary Service to the SoftDevice] */
    // Add a custom base UUID.
    err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type);
    VERIFY_SUCCESS(err_code);
    
    ble_uuid.type = p_nus->uuid_type;
    ble_uuid.uuid = BLE_UUID_NUS_SERVICE;
    
    // Add the service.
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                        &ble_uuid,
                                        &p_nus->service_handle);

    3. Set the correct UUID type when adding the RX and TX characteristics

    The following macros, 

    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_TX_CHARACTERISTIC);

    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_RX_CHARACTERISTIC);

    must be replaced with 

    ble_uuid.type = p_nus->uuid_type;
    ble_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;

    ble_uuid.type = p_nus->uuid_type;
    ble_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;

    as shown in the snippet below

    /**@brief Function for adding RX characteristic.
     *
     * @param[in] p_nus       Nordic UART Service structure.
     * @param[in] p_nus_init  Information needed to initialize the service.
     *
     * @return NRF_SUCCESS on success, otherwise an error code.
     */
    static uint32_t rx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
    {
        /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
        ble_gatts_char_md_t char_md;
        ble_gatts_attr_md_t cccd_md;
        ble_gatts_attr_t    attr_char_value;
        ble_uuid_t          ble_uuid;
        ble_gatts_attr_md_t attr_md;
    
        memset(&cccd_md, 0, sizeof(cccd_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    
        cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.notify = 1;
        char_md.p_char_user_desc  = NULL;
        char_md.p_char_pf         = NULL;
        char_md.p_user_desc_md    = NULL;
        char_md.p_cccd_md         = &cccd_md;
        char_md.p_sccd_md         = NULL;
    
        ble_uuid.type = p_nus->uuid_type;
        ble_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;
    
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 1;
    
        memset(&attr_char_value, 0, sizeof(attr_char_value));
    
        attr_char_value.p_uuid    = &ble_uuid;
        attr_char_value.p_attr_md = &attr_md;
        attr_char_value.init_len  = sizeof(uint8_t);
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = BLE_NUS_MAX_RX_CHAR_LEN;
    
        return sd_ble_gatts_characteristic_add(p_nus->service_handle,
                                               &char_md,
                                               &attr_char_value,
                                               &p_nus->rx_handles);
        /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
    }
    
    
    /**@brief Function for adding TX characteristic.
     *
     * @param[in] p_nus       Nordic UART Service structure.
     * @param[in] p_nus_init  Information needed to initialize the service.
     *
     * @return NRF_SUCCESS on success, otherwise an error code.
     */
    static uint32_t tx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
    {
        ble_gatts_char_md_t char_md;
        ble_gatts_attr_t    attr_char_value;
        ble_uuid_t          ble_uuid;
        ble_gatts_attr_md_t attr_md;
    
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.write         = 1;
        char_md.char_props.write_wo_resp = 1;
        char_md.p_char_user_desc         = NULL;
        char_md.p_char_pf                = NULL;
        char_md.p_user_desc_md           = NULL;
        char_md.p_cccd_md                = NULL;
        char_md.p_sccd_md                = NULL;
    
        ble_uuid.type = p_nus->uuid_type;
        ble_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;
    
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 1;
    
        memset(&attr_char_value, 0, sizeof(attr_char_value));
    
        attr_char_value.p_uuid    = &ble_uuid;
        attr_char_value.p_attr_md = &attr_md;
        attr_char_value.init_len  = 1;
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = BLE_NUS_MAX_TX_CHAR_LEN;
    
        return sd_ble_gatts_characteristic_add(p_nus->service_handle,
                                               &char_md,
                                               &attr_char_value,
                                               &p_nus->tx_handles);
    }

    Best regards
    Bjørn

Reply
  • HI Lee, 

    Which SDK version are you using? SDK v12.3.0?

    The Nordic UART Service(NUS) is a Vendor Specific Bluetooth Service, not a Bluetooth SIG Service. So you need to make the following changes:

    1. Setting the UUIDs to advertise

    static ble_uuid_t                       vive_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, BLE_UUID_TYPE_BLE}};  /**< Universally unique service identifier. */

    must be changed to 

    static ble_uuid_t vive_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, BLE_UUID_TYPE_VENDOR_BEGIN}}; /**< Universally unique service identifier. */

    2. Adding the Vendor Specific UUID

    // Add the service.
    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_SERVICE);
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,&ble_uuid,&p_nus->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    

    must be changed to the following

    ble_uuid_t            ble_uuid;
    ble_uuid128_t         nus_base_uuid = NUS_BASE_UUID;
    
    /**@snippet [Adding proprietary Service to the SoftDevice] */
    // Add a custom base UUID.
    err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type);
    VERIFY_SUCCESS(err_code);
    
    ble_uuid.type = p_nus->uuid_type;
    ble_uuid.uuid = BLE_UUID_NUS_SERVICE;
    
    // Add the service.
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                        &ble_uuid,
                                        &p_nus->service_handle);

    3. Set the correct UUID type when adding the RX and TX characteristics

    The following macros, 

    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_TX_CHARACTERISTIC);

    BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_NUS_RX_CHARACTERISTIC);

    must be replaced with 

    ble_uuid.type = p_nus->uuid_type;
    ble_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;

    ble_uuid.type = p_nus->uuid_type;
    ble_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;

    as shown in the snippet below

    /**@brief Function for adding RX characteristic.
     *
     * @param[in] p_nus       Nordic UART Service structure.
     * @param[in] p_nus_init  Information needed to initialize the service.
     *
     * @return NRF_SUCCESS on success, otherwise an error code.
     */
    static uint32_t rx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
    {
        /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
        ble_gatts_char_md_t char_md;
        ble_gatts_attr_md_t cccd_md;
        ble_gatts_attr_t    attr_char_value;
        ble_uuid_t          ble_uuid;
        ble_gatts_attr_md_t attr_md;
    
        memset(&cccd_md, 0, sizeof(cccd_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
    
        cccd_md.vloc = BLE_GATTS_VLOC_STACK;
    
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.notify = 1;
        char_md.p_char_user_desc  = NULL;
        char_md.p_char_pf         = NULL;
        char_md.p_user_desc_md    = NULL;
        char_md.p_cccd_md         = &cccd_md;
        char_md.p_sccd_md         = NULL;
    
        ble_uuid.type = p_nus->uuid_type;
        ble_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;
    
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 1;
    
        memset(&attr_char_value, 0, sizeof(attr_char_value));
    
        attr_char_value.p_uuid    = &ble_uuid;
        attr_char_value.p_attr_md = &attr_md;
        attr_char_value.init_len  = sizeof(uint8_t);
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = BLE_NUS_MAX_RX_CHAR_LEN;
    
        return sd_ble_gatts_characteristic_add(p_nus->service_handle,
                                               &char_md,
                                               &attr_char_value,
                                               &p_nus->rx_handles);
        /**@snippet [Adding proprietary characteristic to S110 SoftDevice] */
    }
    
    
    /**@brief Function for adding TX characteristic.
     *
     * @param[in] p_nus       Nordic UART Service structure.
     * @param[in] p_nus_init  Information needed to initialize the service.
     *
     * @return NRF_SUCCESS on success, otherwise an error code.
     */
    static uint32_t tx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
    {
        ble_gatts_char_md_t char_md;
        ble_gatts_attr_t    attr_char_value;
        ble_uuid_t          ble_uuid;
        ble_gatts_attr_md_t attr_md;
    
        memset(&char_md, 0, sizeof(char_md));
    
        char_md.char_props.write         = 1;
        char_md.char_props.write_wo_resp = 1;
        char_md.p_char_user_desc         = NULL;
        char_md.p_char_pf                = NULL;
        char_md.p_user_desc_md           = NULL;
        char_md.p_cccd_md                = NULL;
        char_md.p_sccd_md                = NULL;
    
        ble_uuid.type = p_nus->uuid_type;
        ble_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;
    
        memset(&attr_md, 0, sizeof(attr_md));
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
    
        attr_md.vloc    = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth = 0;
        attr_md.wr_auth = 0;
        attr_md.vlen    = 1;
    
        memset(&attr_char_value, 0, sizeof(attr_char_value));
    
        attr_char_value.p_uuid    = &ble_uuid;
        attr_char_value.p_attr_md = &attr_md;
        attr_char_value.init_len  = 1;
        attr_char_value.init_offs = 0;
        attr_char_value.max_len   = BLE_NUS_MAX_TX_CHAR_LEN;
    
        return sd_ble_gatts_characteristic_add(p_nus->service_handle,
                                               &char_md,
                                               &attr_char_value,
                                               &p_nus->tx_handles);
    }

    Best regards
    Bjørn

Children
No Data
Related