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

added service nRF51 SDK9

I added service into ble_app_template

in static void services_init(void) {}

like this

#define NUS_BASE_UUID {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}}

#define BLE_UUID			0x0005 

ble_uuid128_t base_uuid = NUS_BASE_UUID;   
ble_uuid_t    ble_uuid = { . uuid = BLE_UUID }; 
uint32_t 	  err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type);
APP_ERROR_CHECK(err_code);

uint16_t      service_handle;		  
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &service_handle);  
APP_ERROR_CHECK(err_code);	

sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG);

Why I don't see in my smartfone this service added?

  • Use "nrf Connect" to connect with your device ,then check if there is an unknown service has the same uuid with yours.

    It seems that you are adding a vendor defined uuid .You should describe your question more detailed. You don't see this service ,by scanning or connecting ? If scan ,you should add uuid to advertising packet, if connected, you should check your initialization procedure.

    Hi: I don't think it's right. ----> #define BLE_UUID 0x0005 Look at this defination : uint16_t uuid; /**< 16-bit UUID value or octets 12-13 of 128-bit UUID. */

    If your UUID is true service uuid,the right value should be 0x0000 , 12-13 of 128-bit UUID. But you can see that ,its name is NUS_BASE_UUID. You know? It's a basal uuid.

    12-13 of nus service is defined by nordic ,you can not change it . As I know , ble uart service's (nus) UUID is 0x0001

    #define BLE_UUID_NUS_SERVICE 0x0001
    #define BLE_UUID_NUS_TX_CHARACTERISTIC 0x0002/**< The UUID of the TX Characteristic. */
    #define BLE_UUID_NUS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic.*/
    
  • Thanks for answer. There are two projects in examples (SDK9): 1- ble_app_uart_s130 I call

    services_init();
    

    where I call

    err_code = ble_nus_init(&m_nus, &nus_init);
    

    where I added UUID

    ble_uuid128_t nus_base_uuid = NUS_BASE_UUID;
    ...
    err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type);
    

    And at this case I can observer on my smartfone (central role) this UUID when discovered.

    2- In those examples we have ble_app_template where I insert same code like previwes example into

    static void services_init(void)
    {
        /* YOUR_JOB: Add code to initialize the services used by the application.
        uint32_t                           err_code;
        ble_xxs_init_t                     xxs_init;
        ble_yys_init_t                     yys_init;
    
        // Initialize XXX Service.
        memset(&xxs_init, 0, sizeof(xxs_init));
    
        xxs_init.evt_handler                = NULL;
        xxs_init.is_xxx_notify_supported    = true;
        xxs_init.ble_xx_initial_value.level = 100; 
        
        err_code = ble_bas_init(&m_xxs, &xxs_init);
        APP_ERROR_CHECK(err_code);
    
        // Initialize YYY Service.
        memset(&yys_init, 0, sizeof(yys_init));
        yys_init.evt_handler                  = on_yys_evt;
        yys_init.ble_yy_initial_value.counter = 0;
    
        err_code = ble_yy_service_init(&yys_init, &yy_init);
        APP_ERROR_CHECK(err_code);
        */
    			
    	ble_uuid128_t base_uuid = NUS_BASE_UUID;   
    	ble_uuid_t    ble_uuid = { . uuid = BLE_UUID }; 
        uint32_t 	  err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type);
        APP_ERROR_CHECK(err_code);
      
    	uint16_t      service_handle;		  
        err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &service_handle);  
        APP_ERROR_CHECK(err_code);	
    	
    	sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_TAG);
    }
    

    but now I can't see on my smartfone same service. Why?

Related