Widget idea: BLE Battery Service

Posted on
  • Hi. I was thinking it would be nice if the Bangle could advertise it's battery level (so Home Assistant can remind to charge it, for example).

    Does anything like this exist? Is a widget the right way to do it? Something like this works for me.

    (() => {
      function advertiseBattery() {
        NRF.setAdvertising([
          {0x180F : [E.getBattery()]},
        ]);
      }
      
      setInterval(advertiseBattery, 60 * 1000);
      advertiseBattery();
      
      // add your widget
      WIDGETS["ble_battery_service"]={
        area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right)
        width: 0, // how wide is the widget? You can change this and call Bangle.drawWidgets() to re-layout
        draw: function() {} // called to draw the widget
      };
    })()
    

    I'll open a PR if this is sensible. Thanks.

  • What would happen if another app or widget also called NRF.setAdvertising()? Would one overwrite the other? I can see that being a problem.

  • Hi - that sounds like a good idea...

    But yes, multiple calls to NRF.setAdvertising() could overwrite each other. To work around it you could do:

    if (!Bangle.bleAdvert) Bangle.bleAdvert = {};
    function advertiseBattery() {
      Bangle.bleAdvert[0x180F] = [E.getBattery()];
       NRF.setAdvertising(Bangle.bleAdvert);
    }
    

    Then as long as other apps followed the same form they could all work together

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

Widget idea: BLE Battery Service

Posted by Avatar for user91203 @user91203

Actions