• Hi! You don't want to be calling setServices twice - since the second will overwrite the first, so you want to just put the two sets of services together:

    NRF.setServices({
      0x180F : {
        0x2A19 : {
          value : Puck.getBatteryPercentage(),  readable : true
        }
      },
      "8093A600-DC1B-4C75-A61C-37BB61E00F1B" : {
        "8093A601-DC1B-4C75-A61C-37BB61E00F1B" : { // **
          value : 0x00, // optional
          broadcast : false, // optional, default is false
          readable : true,   // optional, default is false
          writable : false,   // optional, default is false
          notify : true,   // optional, default is false
        },
        "8093A602-DC1B-4C75-A61C-37BB61E00F1B" : { // **
          value : 0x0, // optional
          broadcast : false, // optional, default is false
          readable : true,   // optional, default is false
          writable : false,   // optional, default is false
          notify : true,   // optional, default is false
         },
        
        "8093A603-DC1B-4C75-A61C-37BB61E00F1B" : { // **
          value : 0x0, // optional
          broadcast : false, // optional, default is false
          readable : true,   // optional, default is false
          writable : true,   // optional, default is false
          notify : false,   // optional, default is false
        },
      }
    } 
    ...
    

    However the advertising services is a problem. The issue is that there's just too much data. 128 bit services are 16 bytes long. The UART is 128 bits, so you're trying to fit 2+16+16=34 bytes into an advertising scan response packet which can only be 31 bytes.

    At that point Puck.js should error, but it only knows there's a problem when it restarts the BLE stack which it does when you disconnect from BLE - so you can't see it (the lack of reporting is a bug which I'll try and fix).

    So you have some options, none of which are great:

    • Use setScanResponse to overwrite the scan response packet and remove the UART service UUID. You can still access the UART, it just won't be advertised as being there. You'll have to manually construct the scan response packet as an array though.
    • Use setAdvertising with a fully manually constructed advertising packet which contains your 128 bit UUID, then only advertise the 16 bit one in setServices.

    Hope that's some help!

  • Thanks Gordon -- I forgot the UART service is a 128-bit UUID. Now that makes perfect sense. Same with overwriting with the two calls.

    I'm a bit confused about the interaction between NRF.setServices(..., {advertise:[ ... ]}) and the scan response package. What is normally/automatically put in the scan response? The documentation is kind of thin on this.

    I'm fine with not advertising the UART service (but having it useable). I'm actually fine with not advertising my service either, but having it show up once I connect. How can I control this a bit better?

    Maybe a short example if you have one?

    Thanks!
    Bill

About

Avatar for Gordon @Gordon started