pc-ble-driver-js icon indicating copy to clipboard operation
pc-ble-driver-js copied to clipboard

How do i maintain connect after called connect method?

Open mitoconcrete opened this issue 5 years ago • 6 comments
trafficstars

Hi! I have a auto-disconnect issue. That issus is occured after called connect method. Connect is very very good working, but after about 40sec all kit disconnect automatically. I think that is connectParameter setting problem. But I don't know how to set parameters for remain connection. Please Help me. Thanks!

Below code is my connect parameters settings and using connect method information.

 const scanParameters = {
      active: true,
      interval: 100,
      window: 50,
      timeout: 20,
    };
 const connParams = {
      min_conn_interval: 7.5,
      max_conn_interval: 7.5,
      slave_latency: 10,
      conn_sup_timeout: 4000,
    };
const Params = {
      scanParams: scanParameters,
      connParams: connParams,
}

https://nordicsemiconductor.github.io/pc-ble-driver-js/Adapter.html#connect

mitoconcrete avatar Apr 17 '20 07:04 mitoconcrete

This still happens. Mac OS, node v12

Any idea how to resolve this?

ShaharHD avatar Mar 17 '21 17:03 ShaharHD

nope i dont resolve this problem yet. in Window 10, node v12.

mitoconcrete avatar Mar 17 '21 17:03 mitoconcrete

I see the disconnect happening around 30 seconds everytime. During those 30 seconds everything works - no idea what's causing this disconnect.

Maybe there's an undocumented "keep alive" somewhere in https://github.com/NordicSemiconductor/pc-nrfconnect-ble ? ...been looking there for clues.

@kenr is this a known issue?

ShaharHD avatar Mar 17 '21 18:03 ShaharHD

@kenr @mitoconcrete I've created a sample project: https://github.com/WeCanDoIT-Ltd/pc-ble-driver-js-test

which shows the exact issue by using the ble_app_uart from the nrf5_sdk examples.

It will connect, subscribe for the TX event - but will not receive notifications and will disconnect for some reason after 30 seconds or so.

I've verified subscription works by adding the following to nus_data_handler in main.c :

    else if (p_evt->type == BLE_NUS_EVT_COMM_STARTED)
    {
        NRF_LOG_INFO("BLE_NUS_EVT_COMM_STARTED");
    }
    else if (p_evt->type == BLE_NUS_EVT_COMM_STOPPED)
    {
        NRF_LOG_INFO("BLE_NUS_EVT_COMM_STOPPED");
    }

Created a public question on devzone as well: https://devzone.nordicsemi.com/f/nordic-q-a/72937/pc-ble-driver-js-disconnects-after-30-seconds-for-no-reason in case someone has an idea

ShaharHD avatar Mar 17 '21 22:03 ShaharHD

Updated my test (https://github.com/WeCanDoIT-Ltd/pc-ble-driver-js-test) to try and follow https://devzone.nordicsemi.com/f/nordic-q-a/57789/connecting-to-device-using-pc-ble-driver-py-causes-disconnect-after-60-seconds

But it seems unrelated as changing NEXT_CONN_PARAMS_UPDATE_DELAY has no affect on the disconnect timeout

ShaharHD avatar Mar 18 '21 11:03 ShaharHD

I think I resolved the issue - but it might varies with other projects.

In my case, I needed to add handling for the following events and respond

adapter.on('attMtuRequest', (device, newMtu) => {
    adapter.attMtuReply(device.instanceId, newMtu, (err, mtu) => {});
});

adapter.on('dataLengthUpdateRequest', (device, newOctets) => {
    adapter.dataLengthUpdate(device.instanceId, newOctets, () => {});
});

Also make sure you have this handled as well:

adapter.on('connParamUpdateRequest', (device, connectionParameters) => {
    console.log(`connParamUpdateRequest: ${JSON.stringify(connectionParameters)}.`);

    adapter.updateConnectionParameters(device.instanceId, connectionParameters, (err) => {
        if (err) {
          console.log(`updateConnectionParameters Failed: ${err.message}.`);
          return;
        }

        // You can trigger here your processing of the connected device
    });
});

If you're still getting disconnected, the fastest way IMHO to discover which requests you are not responding to is as follows:

  • Open node_modules/pc-ble-driver-js/api/adapter.js
  • Add in _eventCallback(eventArray) the following to filter array which lists event IDs you want to avoid printing (otherwise it's overwhelming)
const filterLog = [
    this._bleDriver.BLE_GATTC_EVT_CHAR_DISC_RSP, 
    this._bleDriver.BLE_GAP_EVT_ADV_REPORT,
    this._bleDriver.BLE_GATTC_EVT_READ_RSP,
    this._bleDriver.BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP,
];

Follow by adding just below this.emit('logMessage', logLevel.DEBUG, text.toString()); the following:

if (filterLog.includes(event.id) === false) {
    console.log(text.toString());
}

and then try and follow which events you are not responding to and getting disconnected or timed-out on (aka Disconnect Reason).

ShaharHD avatar Mar 19 '21 19:03 ShaharHD