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

Add / remove custom service/charac work only if ….. !!!

Hi,

I started my project from the “BLE Characteristics, a beginner's tutorial” I download this project and add it to my SDK_11.0.0_89a8197 . Then I started to modify the code like adding i2c communication, reading values from different sensors that I have in my board, adding new custom UUID service/ characteristic and everything work perfectly. I even develop my own android APP and things work fine. I have been working on this project since 4 months.

But these last days when I tried to make some modification in my services/characteristic by adding new one, remove some of them I notice a WEIIRD behavior.

For example I have actually 5 services that I created before, if I try to remove one of them by uncommenting the init function related to the service in the main file it won't be removed.

image description

In the photo above i uncomment the init service declaration of the last two one from the service_init() inside the main and then I compile the project and load it to my board. after that i open the 'nRF Connect' APP to discover my nRF BLE services/Characteristic and I notice that all the services that I remove it still there.

I stay days to figure out why sometimes in rare occasion the beacon accept the modification that I made about the service/characteristics and sometimes no. And I discover it HOW!!!!

it work only When I left the 'nRF Connect' APP open and I flash my Nrf. The App will be disconnected and when the memory flashing will finish I click on the connect and GUESS WHAT!! now the modification was taken into consideration.

IT's weird but that what I got, this is a little video that I upload it on youtube to demonstrate what I just says :

www.youtube.com/watch

Any idea ?


Update :

I think may be it's comming from the phone it self. once the connection established for the first time with the BLE peripheral, the phone will memeorize the BLE with Services/Characteristic it have.

  • Try setting the IS_SRVC_CHANGED_CHARACT_PRESENT flag:

    #define IS_SRVC_CHANGED_CHARACT_PRESENT  1  
    

    This flag is used to indicate to connected devices that services have changed (i.e., added, removed or modified).

  • i think i may found where the problem came from.

    normally it came from the advertisement packet.

    when i looked into the code and i checked the advertising_init() function i discovered that the scan response packet 'srdata' wasn't updated.

    static ble_uuid_t       m_adv_uuids[] = {{BLE_UUID_OUR_SERVICE_UUID, BLE_UUID_TYPE_VENDOR_BEGIN}}; 
    //.
    //.
    //.
    //.
    ble_advdata_t srdata;
    memset(&srdata, 0, sizeof(srdata));
    srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    srdata.uuids_complete.p_uuids = m_adv_uuids;
    
    err_code = ble_advertising_init(&advdata, &srdata, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
    

    i notice that only the service UUID form the example was sent as scan response. should i add the UUID of the other services that i created ? and how ?

    and how about the characteristic UUID ? only services UUID ?

    normally if i add the other UUIDs services for the scan response will this fix my problem ?

Related