How to minimize the total time of reading characteristics value while using pc-ble-driver-js ?

Hi,

my setup
Central is a nodejs app using pc-ble-driver-js
Our peripheral is nrf52840

I read the examples and they help me a lot so thanks!

Currently when I try to read (in central side)characteristics value (total of 19  characteristics ) the total time is 2.5 secs ..which is a lot (since in your physical layer you mention that speed is 1Mbs).

 const services = await bleManager.getServices(this.device.instanceId);

        for (const service of services) {
            const characteristics = await bleManager.getCharacteristicsByService(service.instanceId);

            for (const characteristic of characteristics) {
              
              if (readableCharacteristic.includes(characteristic.uuid as characteristicEnum)) {
                
                if (additionalChars.includes(characteristic.uuid as characteristicEnum) || 
                  connectionChars.includes(characteristic.uuid as characteristicEnum))  {

                  const value = await bleManager.getCharacteristicValueBy(characteristic.instanceId);
                  this.characteristics[characteristic.uuid as characteristicEnum] = { value: value,id: characteristic.instanceId};
                  
                } else {
                  this.characteristics[characteristic.uuid as characteristicEnum] = { value: null,id: characteristic.instanceId};
                }
              } else {
                this.characteristics[characteristic.uuid as characteristicEnum] = { value: null,id: characteristic.instanceId};
              }
            } 
        }
 

  public async getCharacteristicValueBy(CharacteristicInstanceId) : Promise<number[]>{
    return new Promise((resolve, reject)=> {
      this.ble.adapter.readCharacteristicValue(CharacteristicInstanceId, (err, value) => {
        if (err) {
          reject(Error(`failed to read value ${CharacteristicInstanceId}`));
        } else {
          resolve(value)
        } 
      });
    });
  }

Is there a way to make it faster ?

Thanks,

Ben

Parents Reply
  • Hi Tesc,
    We already set it to 7.5 sec.
    our connection config is:

        "pcBleDriver": {
          "baudRate": "1000000",
          "version": 5,
          "logSeverity": 3,
          "scanParameters": {
            "interval": 100,
            "window": 50,
            "timeout": 1
          },
          "useLNA": false,
          "connectionParameters": {
            "minConnectionInterval": 7.5,
            "maxConnectionInterval": 7.5,
            "slaveLatency": 0,
            "connectionSupervisionTimeout": 2000
          }
        }

    Would you recommend for any change which will make it faster ?
    Thanks,

    Ben

Children
  • Hi,

    If you know the GATT database, then instead of doing service discovery, you could read the characteristic value directly through using the correct ATT handle.

    Regards,
    Terje

  • Are you referring to instance id of each characteristic?
    If so, I did it already(please check the post added code).

    I will try to explain our full flow in each connection:
     1. getServices(used to be getAttributes , but we change it because it cost less time)
     2. foreach services:
          2.1 getCharacteristics By Service id
              2.1.1 foreach characteristics
                      2.1.1.1 getCharacteristicValue by Characteristic instance id 

    if not, please let me know how can I make it faster?
    I know that instanceId of each Characteristic, can I used it to make it faster ?

    Thanks,
    Ben

  • Hi,

    I see you have reposted some of the questions, see the other thread for answers to that part.

    If you already have the instanceId of the characteristic, without doing the service discovery, then maybe it can be used directly? I.e. store it from one run and use it in subsequent runs for the same (or identical) devices? However I am not sure if the instanceId points into a structure that gets built when doing service discovery, or if it just points to the handle. I am still waiting for clarification from the team responsible for pc-ble-driver-js on that.

    Regards,
    Terje

Related