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

Bluetooth doesn't reconnect

Hi,

I have modified nrf5-ble-mpu-data-ready-interrupts from nrf5-mpu-examples, the example works as expected. I have modified it a lot.

Now when I try to reconnect, it doesn't connect and connecting icon appears on screen. I have tested on both Android and IOS. Initially when I connect it gets connected, also it gets disconnected. When I try to connect it again it doesn't. Where have I messed up? 

Thanks

  • It may be many things that occur here, but you should make sure that after you disconnect, then the periheral will start advertising again. You should also check if you have any asserts in your application, an assert will typically trigger app_error_handler(), thereby you should be able to see where it asserts and based on the error code be able to fix the issue. Logging all the BLE events to for instance UART may also be good idea, for instance to see if there is any events that are not handled.

  • Thank you. I will look for it.

    In nRF Connect app it shows "Error 133 (0x85): GATT ERROR"

    It doesn't advertise after disconnection. I even tried  closing the mobile application and tried scanning again, it didn't show up.

    Below is my ble_evt_handler function.

    static void ble_evt_handler(ble_evt_t * p_ble_evt, void * p_context )//const * p_ble_evt, void * p_context)
    {
        ret_code_t err_code = NRF_SUCCESS;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_DISCONNECTED:
    				
    				NRF_LOG_INFO("Disconnected.");
    				// LED indication will be changed when advertising starts.
    			 //NRF_LOG_INFO("Disconnected, reason 0x%x.",p_gap_evt->params.disconnected.reason);
    							SEGGER_RTT_printf(0,"Disconnected\n");
    				
                break;
    
            case BLE_GAP_EVT_CONNECTED:
                NRF_LOG_INFO("Connected.");
    				SEGGER_RTT_printf(0,"Connected..\n");
                err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                APP_ERROR_CHECK(err_code);
                m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                break;
    
    #ifndef S140
            case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
            {
                NRF_LOG_DEBUG("PHY update request.");
                ble_gap_phys_t const phys =
                {
                    .rx_phys = BLE_GAP_PHY_AUTO,
                    .tx_phys = BLE_GAP_PHY_AUTO,
                };
                err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
                APP_ERROR_CHECK(err_code);
            } break;
    #endif
    
            case BLE_GATTC_EVT_TIMEOUT:
                // Disconnect on GATT Client timeout event.
                NRF_LOG_DEBUG("GATT Client Timeout.");
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_TIMEOUT:
                // Disconnect on GATT Server timeout event.
                NRF_LOG_DEBUG("GATT Server Timeout.");
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_EVT_USER_MEM_REQUEST:
                err_code = sd_ble_user_mem_reply(p_ble_evt->evt.gattc_evt.conn_handle, NULL);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
            {
                ble_gatts_evt_rw_authorize_request_t  req;
                ble_gatts_rw_authorize_reply_params_t auth_reply;
    
                req = p_ble_evt->evt.gatts_evt.params.authorize_request;
    
                if (req.type != BLE_GATTS_AUTHORIZE_TYPE_INVALID)
                {
                    if ((req.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ)     ||
                        (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) ||
                        (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL))
                    {
                        if (req.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
                        {
                            auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
                        }
                        else
                        {
                            auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
                        }
                        auth_reply.params.write.gatt_status = APP_FEATURE_NOT_SUPPORTED;
                        err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gatts_evt.conn_handle,
                                                                   &auth_reply);
                        APP_ERROR_CHECK(err_code);
                    }
                }
            } break; // BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST
    
            default:
                // No implementation needed.
                break;
        }
        
        ble_mpu_on_ble_evt(&m_mpu, p_ble_evt);
    }

    Thanks

  • That error code can mean many things, I suggest that you search for "Error 133 (0x85): GATT ERROR" on google to see if any apply to you. If you want me to look into this in more details I suggest you create a nRF sniffer for a scenario that fails and one that works.

Related