• Hi,

    sorry for opening a new topic again already, but I hope that our notes might help somebody else later on.

    Right now I am connecting like this to my bike sensor:

    NRF.requestDevice({ timeout:5000, filters: [{ services: "0x1816"  /* namePrefix: 'Wahoo' */ }] }).then(function(device) {
      console.log(device);
      return device.gatt.connect();
      }).then(function(gatt_object) {
        gatt = gatt_object;
        s = "Looking for service...";
        g.clear(); g.drawString(s ,0 ,0); g.flip();
        return gatt.getPrimaryService("1816");
        }).then(function(service) {
          s = "Looking for char...";
          g.clear(); g.drawString(s ,0 ,0); g.flip();
          return service.getCharacteristic("0x2A5B");
        }).then(function(characteristic) {
          characteristic.on('characteristicvaluech­anged', OnNotify);
          return characteristic.startNotifications();
          }).then(function() {
            connected = true;
            t = getTime();
            setDisplayMode("livedata");
            gatt.device.on('gattserverdisconnected',­ function(reason) {console.log("gattserverdisconnected, Grund: "+ reason+" Zeit: " + (getTime() -t) + " sec"); disconnect(reason);} ); 
    }
    

    Initially, I even had a timeout of 20 seconds in requestDevice, which led to pretty unreliable connection intitation.
    With nrfConnect I see that the sensor starts advertising really fast with an interval of 330ms initially.
    I wonder if it is possible to cut the timeout short (right now it seems that the code scans for the full timeout before handing back scan results) and return a matching device immediately?

    Or is it preferable to cache the sensor's address and do a direct connect to that later on? That would have the (very small) drawback of needing additional logic to do a full scan if the previous/cached device is not successfully connected, to enable connecting to new/other sensors.

    Thanks,

    Joost

About

Avatar for Joost @Joost started