Custom bluetooth service on bangle.js

Posted on
  • I've started building a web app that can connect to the bangle and send commands via bluetooth. All works well when using the built in service/characteristic:

    const bluetoothServiceUUID: BluetoothServiceUUID = '6e400001-b5a3-f393-e0a9-e50e24dcca9e';
    const bluetoothCharacteristicUUID: BluetoothCharacteristicUUID = '6e400002-b5a3-f393-e0a9-e50e24dcca9e';
    

    however my aim is to stream accelerometer data from the watch, so I've been trying to write a watch app that exposes a custom service/characteristic to do this.

    This is my first espruino device and my first use of web bluetooth - but as a start and following the code from this puck project: https://github.com/AkosLukacs/PuckStream­ing/blob/master/src/PuckStreaming.js I've written a really simple watch app that I expected to expose a service that I can just read a value from -

    function onInit() {
      NRF.setServices({
        '92c1b5b8-e824-4938-bbed-672529103e56': {
          '92c1b5b8-e825-4938-bbed-672529103e56': {
            notify: true,
            readable: true,
            broadcast: true,
            value: "Hello"
          }
        }
      });
      E.showMessage("Waiting..","Bluetooth Connection");
    }
    
    onInit();
    

    Opening the app on the watch and then attempting to use this service and characteristic from the web app I get:

    No Services matching UUID 92c1b5b8-e824-4938-bbed-672529103e56 found in Device.
    

    Please can someone point me in the right direction as to why this isn't working?

  • Tue 2020.04.14

    Could it be a 'Puck' is not a 'Bangle'?

    https://www.espruino.com/About+Bluetooth­+LE

    https://www.bluetooth.com/blog/a-develop­ers-guide-to-bluetooth/

    How to create custom service and characteristics

    Shouldn't the service and characteristic differ?

  • You have to disconnect from the device for service advertisements to actually update.
    Just tested your above snippet, and the new service shows up in nRF Connect, and does have a value of "Hello".
    Get nRF Connect for your phone, makes quick checks really easy.

  • Thanks for the links. I'm aware that puck is not a bangle, however since they both based on Espruino and the bangle reference includes these features then I assumed the code would be pretty cross compatible.

    The characteristic and service are different - just by one character.

  • @AkosLukacs Thanks for the reply! It seems I am on the right lines then - however

    'I have to disconnect from the device for the service advertisements to actually update'

    Maybe there is something wrong in my fundamental understanding - I have saved the watch app into the device storage, I run the app on the watch with no devices connected, then attempt to connect to the watch. By disconnect do you mean completely unpair and then repair? I'll give that a try!

    I'll definitely take your advice and get that app, it sounds like it could be really useful.

  • As @AkosLukacs says, this should work - but you have to disconnect from your Bangle to get it to update the services it shows.

  • Oops - sorry forgot to refresh before replying.

    I assumed the code would be pretty cross compatible.

    Yes, it'll be identical. I'm not sure Robin's post is too helpful

    I have saved the watch app into the device storage, I run the app on the watch with no devices connected

    That sounds perfect then. And it's displaying the "Waiting.." message? I guess you could add NRF.disconnect() command after that to force a disconnect.

    By disconnect do you mean completely unpair and then repair?

    You shouldn't need to - however if you are paired with a device then sometimes the computer will try and hang onto the connection even when no app is connected.

    Also, it depends on your device but I believe iPhones especially cache the Bluetooth services - so you need to turn Bluetooth off and on again to get them to load the new services

  • Updated "PuckStreaming" to support the Bangle's accelerometer and magnetometer as well. Did minor tweaks, but the idea is the same as with the Puck.

    The UUID of the characteristic and the magnetometer service is the same, doesn't seem to be any issue. It's a hierarchy, so don't think it shouldn't be the same...

    BTW, doing this one thing didn't work. Just to notice a typo that caused an exception. Hard to find if you are not connected to it at all :)

  • Thanks @AkosLukacs that's really helpful. I hadn't realised when you first responded that it was your code I'd been using!

  • Glad it's useful.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Custom bluetooth service on bangle.js

Posted by Avatar for CharlieD @CharlieD

Actions