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

Getting around with Nrf52840 Dongle using Node.js / pc-ble-driver-js

Hi! We've been trying to get into development with Nrf52840 Dongle using Node.js / pc-ble-driver-js.

We have two dongles, and we just tried to test the heart rate examples with mixed feelings.

- First off, the collector seemed to be working, all well. However, connector threw some errors everytime when trying to connect the two -> Found out there was a bug in the connector code (it keeps trying to connect, even though first connection is still pending, then kicks out). This got fixed.

- Next the connector stopped working. This one I couldn't solve:

** 1. Issue: Running the heart_rate_connector.js connector does not work. Here's the result.

$ node heart_rate_connector.js COM5 v5
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module 'C:\Users\pc-ble-driver-js\examples\heart_rate_connector.js'        
←[90m    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:841:27)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m {
  code: ←[32m'MODULE_NOT_FOUND'←[39m,
  requireStack: []
}

** 2. Issue / Question. How to modify the connector code to work with custom characteristics?

So I have a device with custom characteristics. I know the uuid, but I don't know how the cccd (uint16_t) is created in the sdk?
The connector.js code seems to require cccd uuid to work. Is there a way to just start notifications without knowing it?

I already tried this, but it didn't work like this... (found it from here: https://nordicsemiconductor.github.io/pc-ble-driver-js/Adapter.html ):

    adapter.on('deviceConnected'device => {
        console.log(`Device ${device.address}/${device.addressType} connected.`);

        adapter.startCharacteristicsNotifications(BLE_UUID_CHAR ,false);

We first put some effort into web bluetooth api, there it was pretty much this simple (not functional code, but basic idea is this simple):

    const device = await navigator.bluetooth
    .requestDevice({
      filters:[
        {name:'' ]},
        {services: [serviceUuid]}
      ]
    });
    
    const server = await device.gatt.connect();
    const service = await server.getPrimaryService(serviceUuid);
    const characteristic = await service.getCharacteristic(writableCharacteristicUuid);
    await characteristic.startNotifications();
    characteristic.addEventListener('characteristicvaluechanged', (e)=>{handleNotifications(euuidStr);});
characteristic.writeValueWithResponse(newCmd);

Is there a way to reach something like this? Where I know the characteristic uuid and then just turn notifications on / off, or do I have to first somehow find them etc. ?

  • Hi,

    1. The error message

    Error: Cannot find module 'C:\Users\pc-ble-driver-js\examples\heart_rate_connector.js'

    is a bit strange, as the path C:\Users\ on a Windows system is usually reserved for users, where each folder inside the Users folder is the username of a user. This path is probably not where you have put pc-ble-driver-js?

    Where have you put pc-ble-drive-js, where is the pc-ble-driver-js application that you run, and how do you run it?

    2. In general, in order to turn on notifications, you need to find the characteristic (that you want to get notifications from), and then write to the Client Characteristic Configuration Descriptor on that characteristic. pc-ble-driver-js is a wrapper around serialization of our BLE stack, what we call the SoftDevice, and vendor specific (128 bit) UUIDs are handled differently from 16 bit UUIDs. It may be a good idea to have a look at the documentation for the SoftDevice that you are using. The API calls of the SoftDevice maps to pc-ble-driver-js API calls, and the message sequence charts show how procedures work.

    Regards,
    Terje

Related