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

When I add 2 "service data" in the gap, only the second is showed

Hi all,  ( nRF52 DK, SDK 15.3, S132 )

Many asking about how to add 2 "service data" in the GAP advertising, but no real answer on the solution !

The first service data is a Battery level and is working well, but when I add a second service data this one is displayed and the first one is like overwrited !

Is there something to setup for displaying the 2 service data ?

Hope that I receive the right info or a clear way do it.

Best regards

Jiemde 

  • Hi Jean-Marie, 

    Could you send the code you used ? 

    Note that if you use  ble_advertising library with  ble_advertising_init() function, we don't support the 128 bit service data (AD Type 0x21) yet. The library only support service data 16 bit (ADType 0x16). 

    If you want to advertise with 128 bit UUID service data, you would need to either modify the library, or prepare the raw advertising packet from scratch.

    There is a big chance that the advertising packet is not enough (31 bytes max) and you would need to use the scan response to advertise the 2nd service data (use srdata in addition to advdata)  
    This code worked for me with 2 16 bit service data: 

     ret_code_t             err_code;
        ble_advertising_init_t init;
        static ble_advdata_service_data_t service_data_array[2];
        static uint8_array_t data_array1,data_array2;
        static uint8_t data1[3]={1,2,3};
        static uint8_t data2[3]={3,4,5};
        data_array1.size=3;
        data_array1.p_data=data1;
        
        data_array2.size=3;
        data_array2.p_data=data2;
        service_data_array[0].service_uuid= 0x1234;
        service_data_array[1].service_uuid= 0x5678;
        service_data_array[0].data=data_array1;
        service_data_array[1].data=data_array2;
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance      = true;
        init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        init.advdata.p_service_data_array=service_data_array;
        init.advdata.service_data_count=2;
            init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);

  • Hi Hung,

    Many thanks for your fast reply and your code is working ! :))

    It's not a problem to send you my code but be indulgent I'm very new in C language and Ble is not easy !

    I send you screen capture of the result I must have in final.

    So a service data ( 0x16 ) with the value of the Battery level and an other one

    service data ( 0x21 ) with 128Bit UUID with 4 bytes of data ( in fac the 4 last bytes of the Mac address ! )

    In total I use 30 bytes! so can be advertise in a simple GAP.

    As you say in your reply "The library only support service data 16 bit (ADType 0x16)."

    So what do you propose for solve my need ?

    How can I send you my code file ?

    Hope you can help me.

    Best regards

    Jiemde

  • Hi Jiemde, 

    You would need to encode the service data 128 bit on your own. Please have a look at service_data_encode() function in ble_advdata.c to see how we encode the 16 bit UUID. You need to write a similar function for the 128 bit service data. 

    If you simply want to copy exactly what you have achieved with  Zerynth. You can get the raw data packet from that application and then call sd_ble_gap_adv_set_configure() to set the raw advertising data directly, and call sd_ble_gap_adv_start() to start advertising. 

    There is no easy way to get around this, you want to achieve something a bit advanced and not supported out of the box in our library. Some understanding on  advertising package data encoding is needed. 

  • Hi Hung,

    Thanks for your reply.

    The first solution is not possible for me, as I'm very, very new in C langage and I do not know the command set needed to carry out this work.

    About the second solution could you provide a working example ? or a snippet with the whole process ?

    Thank you very much for your help, I really need help for that development, Thanks!

    Best regards,   Jiemde

  • Please look for "Configuring advertising parameters for an advertising set" inside the migration document pdf file for s132_nrf52_6.0.0. It's located in \components\softdevice\s132\doc 

    We have example code for sd_ble_gap_adv_set_configure() function. 

    I have a blog here that I created long time ago, the APIs have changed, but you can get some information about advertising data packet. 

Related