RSSI + MIT APP INVENTOR + BLE

Hello,

I'm using an nrf52dk board and I am trying to get the RSSI value, and it works fine with the nrfconnect app, except that the the transfer doesn't start at the first connect but just when I connect, disconnect and reconnect the devices(nrf52dk and nrfconnect on android tablet).

My main problem is that when i try to make the same thing with the MIT app inventor application, it doesn't work at all.

I don't get any rssi event change anymore and I was wondering if someone could give me some advice how to solve this problem or another way to see if the distance between the two devices is getting bigger?

Greetins from Switzerland

Ale

static void ble_evt_handler(ble_evt_t 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.
            break;

        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO("Connected.");
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);

            sd_ble_gap_rssi_start(m_conn_handle,1,0);

            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
           
            APP_ERROR_CHECK(err_code);
            break;

        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;

        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_GAP_EVT_RSSI_CHANGED:

        rssi = p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;

        NRF_LOG_INFO("RSSI: %d", rssi);
        break;


        case BLE_GAP_EVT_ADV_REPORT:

        NRF_LOG_INFO("RSSI: %d", p_ble_evt->evt.gap_evt.params.adv_report.rssi);

        APP_ERROR_CHECK(err_code);

        break;

        default:
            // No implementation needed.
            break;
    }
}

  • Hi,

    Strange, I don't see any reasons for it to not start upon the first connection unless the connection isn't successful the first time you try? Could you try setting a breakpoint at the CONNECTED event and see if the program enters it on the first time? Could you do a similar approach and set a breakpoint at the RSSI_CHANGED? 

    regards

    Jared 

Related