This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How is BLE_CONN_HANDLE_INVALID changed in multiple services

How is BLE_CONN_HANDLE_INVALID changed in multiple services

I modified the ble_sdk_app_proximity example. I added x3 services, based on the BLE Characteristics, a beginner's tutorial, and it seems to be working fine. (nrf5-ble-tutorial-characteristic-CompletedCode ported for SDK 13.zip)

The first service, our_service.c from the turorial, works ok. The characteristic gets updated. The additional two (2) services did not until.......

It seems BLE_CONN_HANDLE_INVALID does not get changed to "VALID" or whatever.

So my service 2 and 3 does not update the characteristic.

When I comment out //p_our_service->conn_handle = BLE_CONN_HANDLE_INVALID; both the characteristics of the two additional services are updated.

So it seems the first service determines the connection state. Once it is connected, conn_handle ... stays .... BLE_CONN_HANDLE_INVALID for the other services?

How / where can I change BLE_CONN_HANDLE_INVALID to be "VALID"? (BLE_CONN_HANDLE_ALL)???

Any help appreciated

  • Hi,

    As I think you have seen, the connection handle is set to whatever value the Softdevice decides in the function ble_our_service_on_ble_evt() at line 66, in our_service.c. Furthermore, ble_our_service_on_ble_evt() is called from the function ble_evt_dispatch() at line 551 in main.c. You should make similar functions and function calls for your new services.

    When I comment out //p_our_service->conn_handle = BLE_CONN_HANDLE_INVALID; both the characteristics of the two additional services are updated.

    This doesn't make sense to me. At what line do you comment out this? Line 69 in our_service.c? Are you using the same ble_os_t type variable for all of your services? The one called m_our_service in main.c in the tutorial? If so you should probably make one such variable for each of your services.

  • Martin, I comment it out in the two new xxx_service.c files // OUR_JOB: Step 3.B, Set our service connection handle to default value. I.e. an invalid handle since we are not yet in a connection. //p_ppp_service->conn_handle = BLE_CONN_HANDLE_INVALID;

    NOTE: In either or both, of the new xxx_service.c files, if that line is Uncommented, the service does not get updated. I can still manually read or write to the value, but the auto update does not work, until I comment out //p_xxx_service->conn_handle = BLE_CONN_HANDLE_INVALID;

    I duplicate your our_service.c file, renamed all functions and variables to xxx_service, si I have // ALREADY_DONE_FOR_YOU: Declaration of a function that will take care of some housekeeping of ble connections related to our service and characteristic void ble_ppp_service_on_ble_evt(ble_ps_t * p_ppp_service, ble_evt_t * p_ble_evt)

  • Martin, FIXED the problem Your mentioning of ".. called from the function ble_evt_dispatch() .." made me re-check, and I had the calls for the two new services commented out. (Left over from testing). in ble_evt_dispatch(ble_evt_t * p_ble_evt)

    So I uncommented the 2 new services, and it worked!! Thanks (I also removed the comment for //p_sr2_service->conn_handle = BLE_CONN_HANDLE_INVALID; and //p_sr3_service->conn_handle = BLE_CONN_HANDLE_INVALID;

    // OUR_JOB: Step 3.C, Call ble_our_service_on_ble_evt() to do housekeeping of ble connections related to our service and characteristic
    ble_our_service_on_ble_evt(&m_our_service, p_ble_evt);
    ble_sr2_service_on_ble_evt(&m_sr2_service, p_ble_evt);
    ble_sr3_service_on_ble_evt(&m_sr3_service, p_ble_evt);
    
  • So the problem is solved then?

  • Yes, Thanks. I just wanted to show the fix, incase someone else runs into the same. Sorry, I should have closed this.

Related