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

How to reconnect after disconnecting via iOS app?

I'm using the example ble_app_hrs along with the HRM part of the nRF Toolbox iOS app. It makes sense to handle this in on_ble_evt in main.c but am unclear how I can recover from enter system mode off.

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t        err_code;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            led_stop();
            
            // Initialize the current heart rate to the average of max and min values. So that
            // everytime a new connection is made, the heart rate starts from the same value.
            m_cur_heart_rate = (MAX_HEART_RATE + MIN_HEART_RATE) / 2;

            // Start timers used to generate battery and HR measurements.
            application_timers_start();

            // Start handling button presses
            err_code = app_button_enable();
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_DISCONNECTED:            
            // @note Flash access may not be complete on return of this API. System attributes are now
            // stored to flash when they are updated to ensure flash access on disconnect does not
            // result in system powering off before data was successfully written.

            // Go to system-off mode, should not return from this function, wakeup will trigger
            // a reset.
            system_off_mode_enter();
            break;

        case BLE_GAP_EVT_TIMEOUT:
            if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT)
            {
                led_stop();
                
                nrf_gpio_cfg_sense_input(HR_INC_BUTTON_PIN_NO,
                                         BUTTON_PULL, 
                                         NRF_GPIO_PIN_SENSE_LOW);

                nrf_gpio_cfg_sense_input(HR_DEC_BUTTON_PIN_NO,
                                         BUTTON_PULL, 
                                         NRF_GPIO_PIN_SENSE_LOW);

                system_off_mode_enter();
            }
            break;

        default:
            // No implementation needed.
            break;
    }
}
  • Assuming all other denitializations/initializations specific to your firmware app and the template overhead are handled appropriately, all you really need to do is re-start advertising at that point.

    case BLE_GAP_EVT_DISCONNECTED:    
      /*        
      // @note Flash access may not be complete on return of this API. System attributes are now
      // stored to flash when they are updated to ensure flash access on disconnect does not
      // result in system powering off before data was successfully written.
    
      // Go to system-off mode, should not return from this function, wakeup will trigger
      // a reset.
      system_off_mode_enter();
      */
    
      // TODO: Deinit whatever you need, stop timers, etc
       
      // Restart advertising
      advertising_start();
      break;
    
  • If i want to pair the 51822 with an IOS app some time without the 51822 powre off and on,can i use a button ISR to excute the advertising_start() function? how should i do? thank you in advance!

Related