Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
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

ble_app_multirole_lesc on SDK17.1.0 vs SDK15.2.0

Hi,

I want to use a single firmware to be flashed on two devices that can be used as a ble peripheral with DK Button 3 and as a central with DK Button 4.

I chose ble_app_multirole_lesc for this purpose. I made the following changes:

diff --git a/examples/ble_central_and_peripheral/experimental/ble_app_multirole_lesc/main.c b/examples/ble_central_and_peripheral/experimental/ble_app_multirole_lesc/main.c
index e384712..84442ed 100644
--- a/examples/ble_central_and_peripheral/experimental/ble_app_multirole_lesc/main.c
+++ b/examples/ble_central_and_peripheral/experimental/ble_app_multirole_lesc/main.c
@@ -280,25 +280,6 @@ static void scan_start(void)
 }
 
 
-/**@brief Function for initializing the advertising and the scanning.
- */
-static void adv_scan_start(void)
-{
-    ret_code_t err_code;
-
-    scan_start();
-
-    // Turn on the LED to signal scanning.
-    bsp_board_led_on(CENTRAL_SCANNING_LED);
-
-    // Start advertising.
-    err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
-    APP_ERROR_CHECK(err_code);
-
-    NRF_LOG_INFO("Advertising");
-}
-
-
 /**@brief Function for handling Peer Manager events.
  *
  * @param[in] p_evt  Peer Manager event.
@@ -312,7 +293,6 @@ static void pm_evt_handler(pm_evt_t const * p_evt)
     switch (p_evt->evt_id)
     {
         case PM_EVT_PEERS_DELETE_SUCCEEDED:
-            adv_scan_start();
             break;
 
         default:
@@ -588,8 +568,6 @@ static void on_ble_central_evt(ble_evt_t const * p_ble_evt)
                                                    &target_uuid);
                 APP_ERROR_CHECK(err_code);
             }
-            
-            scan_start();
         } break; // BLE_GAP_EVT_DISCONNECTED
 
         case BLE_GAP_EVT_TIMEOUT:
@@ -693,8 +671,6 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
 
         case BLE_ADV_EVT_IDLE:
         {
-            ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
-            APP_ERROR_CHECK(err_code);
         } break;
 
         default:
@@ -897,6 +873,21 @@ static void bsp_event_handler(bsp_event_t event)
             on_num_comp_button_press(false);
             break;
 
+      case BSP_EVENT_KEY_2:
+            // Start advertising.
+            err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
+            APP_ERROR_CHECK(err_code);
+
+            NRF_LOG_INFO("Advertising");
+            break;
+
+      case BSP_EVENT_KEY_3:
+            scan_start();
+
+            // Turn on the LED to signal scanning.
+            bsp_board_led_on(CENTRAL_SCANNING_LED);
+            break;
+
         default:
             break;
     }
@@ -1161,6 +1152,7 @@ int main(void)
     // Start execution.
     NRF_LOG_INFO("LE Secure Connections example started.");
 
+    erase_bonds = true;
     if (erase_bonds == true)
     {
         delete_bonds();
@@ -1168,7 +1160,6 @@ int main(void)
     }
     else
     {
-        adv_scan_start();
     }
 
     // Enter main loop.

After bonding, it used to work on SDK15.2.0 such that pressing Button 1 on the peripheral side would print 

<info> app: CENTRAL: Heart Rate = 87
on the central side.

But on SDK17.1.0 it does not print anything! What other changes do I need to make it work on the latest SDK?

  • Hi

    The function in the default versions of the multirole example seems to be the same for v15.2.0 and 17.1.0 of the SDK, so there shouldn't be a difference between the two. Can you confirm that you still have the following handling of the BSP_EVENT_KEY_0 on your application?

            case BSP_EVENT_KEY_0:
                err_code = ble_hrs_heart_rate_measurement_send(&m_hrs, 87);
                if ((err_code != NRF_SUCCESS) &&
                    (err_code != NRF_ERROR_INVALID_STATE) &&
                    (err_code != NRF_ERROR_RESOURCES) &&
                    (err_code != NRF_ERROR_BUSY) &&
                    (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
                    )
                {
                    APP_ERROR_HANDLER(err_code);
                }
    
                on_num_comp_button_press(true);
                break;

    Can you confirm that the two devices both use UART as the backend for logging and that UART is enabled in the sdk_config.h header file. 

    Best regards,

    Simon

  • Hi Simon,

    The above diffs are the only changes I made, so BSP_EVENT_KEY_0 and sd_config.h are untouched.

    Both devices use UART and UART backend for logging is set:

    #define NRF_LOG_BACKEND_UART_ENABLED 1

  • Hi

    I just tested the default version of the ble_app_lesc_multirole application in SDK v17.1.0 with a phone running nRFConnect as a central, and after connecting and bonding to the device and enabling notifications I was able to print the CENTRAL: Heart Rate = 87 message to my phone app.

    By "not print anything" do you not see the "LE Secure Connections example started."  message when starting the application either? Are you sure it is connected to the terminal at all? I don't see any reason that these changes should stop the device from printing data to the UART terminal. Does the LEDs light up as expected on the device to indicate that it is advertising/scanning at all?

    It might be that the application is crashing or stuck in a loop somewhere. Have you tried debugging the application at all? You can do so by adding DEBUG to the preprocessor defines of your project and see if you can get any information from that.

    Best regards,

    Simon

  • Hi Simon,

    I have also tested with a phone and did not have any issue. The problem raise when using two DKs.

    The LEDs light up as expected and terminals are connected.

    DK1 (peripheral):

    Welcome to minicom 2.7.1
    
    OPTIONS: I18n 
    Compiled on Dec 23 2019, 02:06:26.
    Port /dev/ttyACM0, 14:09:26
    
    Press CTRL-A Z for help on special keys
    
    <info> app_timer: RTC: initialized.
    <info> app: LE Secure Connections example started.
    <info> app: Erase bonds!
    <info> peer_manager_handler: All peers deleted.
    <info> app: Advertising
    <info> app: PERIPHERAL: Connected, handle 1.
    <info> app: PERIPHERAL: BLE_GAP_EVT_SEC_PARAMS_REQUEST
    <info> app: PERIPHERAL: BLE_GAP_EVT_LESC_DHKEY_REQUEST
    <info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 1
    <info> app: PERIPHERAL: BLE_GAP_EVT_PASSKEY_DISPLAY: passkey=829681 match_req=1
    <info> app: Press Button 1 to confirm, Button 2 to reject
    <info> app: Numeric Match. Conn handle: 1
    <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 1, procedure: Bonding
    <info> app: PERIPHERAL: BLE_GAP_EVT_AUTH_STATUS: status=0x0 bond=0x1 lv4: 1 kdist_own:0x3 kdist_peer:0x2
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Central address resolution, action: Update

    DK2(Central):

    Welcome to minicom 2.7.1
    
    OPTIONS: I18n 
    Compiled on Dec 23 2019, 02:06:26.
    Port /dev/ttyACM1, 14:00:37
    
    Press CTRL-A Z for help on special keys
    
    <info> app_timer: RTC: initialized.
    <info> app: LE Secure Connections example started.
    <info> app: Erase bonds!
    <info> peer_manager_handler: All peers deleted.
    <info> app: Scanning
    <info> app: CENTRAL: Connected, handle: 0.
    <info> app: CENTRAL: Searching for HRS on conn_handle 0x0
    <info> app: CENTRAL: BLE_GAP_EVT_SEC_PARAMS_REQUEST
    <info> app: CENTRAL: BLE_GAP_EVT_LESC_DHKEY_REQUEST
    <info> nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0
    <info> app: CENTRAL: BLE_GAP_EVT_PASSKEY_DISPLAY: passkey=829681 match_req=1
    <info> app: Press Button 1 to confirm, Button 2 to reject
    <info> app: CENTRAL: HRS discovered on conn_handle 0x0
    <info> app: Numeric Match. Conn handle: 0
    <info> peer_manager_handler: Connection secured: role: Central, conn_handle: 0, procedure: Bonding
    <info> app: CENTRAL: BLE_GAP_EVT_AUTH_STATUS: status=0x0 bond=0x1 lv4: 1 kdist_own:0x3 kdist_peer:0x2
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Central address resolution, action: Update

    The application is not crashing because then I added 

    NRF_LOG_INFO("Button 1 pressed!");
    to BSP_EVENT_KEY_0, and I can the print:

    <info> app: Button 1 pressed!

  • Hi,

    This is a bug most likely in nrf_ble_gq module. I have created an internal ticket for this as it seems that it is not that easy to unplug this module from this example since the discovery module and the hrs service depends on it. No workaround that I can see as far as i know, but as soon as we find out the reason, I can update this thread.

Related