• Hi!

    I've had a look through the apps and examples, apologies if I missed it:

    I'm seeking an example of robustly maintaining a connection to a BLE device so we can receive characteristicvaluechanged events.

    I have this so far, but it lacks retrying everything, handling failures, and so on. I'm unfamiliar with JavaScript. If there's no off-the-shelf example of how to be robust, I'll give it a go and share back here...

    NRF.requestDevice({ filters: [{ namePrefix: 'XXXX' }] }).then(function(device) {
      console.log("Found");
      return device.gatt.connect();
    }).then(function(g) {
      console.log("Connected");
      gatt = g;
      return gatt.getPrimaryService(
        ".......");
    }).then(function(service) {
      console.log("Got Service");
      return service.getCharacteristic(
        "......");
    }).then(function (c) {
      console.log("Got Characteristic");
      characteristic = c;
      characteristic.on('characteristicvaluechanged', function(event) {
        console.log("Got event");
        console.log(event.target.value.buffer);
        parseMessage(event.target.value.buffer);
      });
      return characteristic.startNotifications();
    });
    
    
About

Avatar for user145265 @user145265 started