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

Creating a custom ble service

Hello,

I am doing some experiments with 2 pca10001 and the ble_hrs example (with s110, s120). As it works well, I would like to mofify this example to fit my needs. I only need to transfer some booleans, some integers and one or two strings. So I start creating a new custom service based on ble_bas.[ch]. Is it the correct way ? If it is the correct way, I need to add service (BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_MY_NEW_SERVICE). The UUIDs of the different services are defined in ble_srv_common.h What value I can choose for my new custom service ?

Thanks,

Olivier

Parents
  • I was able to register total custom service and characteristics using my own custom Guids, but you have to reverse the Guid bytes so they are in big endian. For example, I generated the following service Guid:

    {227cb85f-855b-4044-9b80-7b8cf0f32854}

    But then in order to register this guid I do this (notice the order of the bytes is reversed):

    ble_uuid128_t ble_uuid128 = { 0x54, 0x28, 0xf3, 0xf0, 0x8c, 0x7b, 0x80, 0x9b, 0x44, 0x40, 0x5b, 0x85, 0x5f, 0xb8, 0x7c, 0x22 };
    uint8_t ble_custom_type;
    ble_uuid_t ble_uuid;
    
    err_code = sd_ble_uuid_vs_add(&ble_uuid128, &ble_custom_type);		
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    

    Now I can use octets 12 and 13 in the service_add call:

    // Use our custom registered service type.
    ble_uuid.type = ble_custom_type;
    blle_uuid.uuid = 0xb85f; // octets 12-13 of 128-bit UUID
    p_pws->uuid = 0xb8f5;
    
    // Initialize service structure
    p_pws->evt_handler = p_pws_init->evt_handler;
    p_pws->conn_handle = BLE_CONN_HANDLE_INVALID;
    	
    // Add service
    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, 
                                                                 &ble_uuid, &p_pws->service_handle);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    

    Same trick works for any custom characteristics. Now when I pair my device and dump the GATT service on my PC I see the service guid: {227cb85f-855b-4044-9b80-7b8cf0f32854}, so everything works great.

  • Yeah, either way the format on the nrf51822 is reverse of that on the PC, so the nrf51822 uses big endian and the PC uses little endian, hence the need to reverse the bits somewhere.

Reply Children
No Data
Related