Get message from Gadgetbridge

Posted on
  • I know how to push something from Bangle to Gadgetbridge.

    Bluetooth.println(JSON.stringify({t:"mus­ic", n:"play"}));
    

    How can I get something from Gadgetbride to Bangle (pulled from Bangle, not pushed by Gadgetbridge)?
    I would like to read music information in an app on the Bangle.

    Thanks

  • You just need to define a function called GB:

      global.GB = (event) => {
        switch (event.t) {
          case "musicinfo":
            ...
            break;
          case "musicstate":
            ...
            break;
        }
      };
    

    More info on what form the data takes is at http://www.espruino.com/Gadgetbridge

  • This would override the GB function if it's already defined, correct? What if multiple apps want to receive events?

  • Okay, I saw that code in the BG widget and I am using it in my app.
    However, I do not know how to trigger it.

    The problem is, that I have to read what is playing, when I start the app.
    Otherwise I cannot show title information and I do not know what the musicstate is.

    global.GB = function(j) {
      if (debug ==1) print("global.GB");
      switch (j.t) {
        case "musicinfo":
          musicInfo = j;
          draw();
          break;
        case "musicstate":
          musicState = j.state;
          draw();
          break;
      }
    };
    
  • This would override the GB function if it's already defined, correct? What if multiple apps want to receive events?

    Yes - however since only one app runs at a time you're kindof ok. The only potential conflict is Widgets - if you're making a 2nd widget that exists alongside Gadgetbridge, or if your app is loading widgets then there's a problem.

    What I'd suggested in another post was just to change everything to do:

    (function() {
      var _GB = global.GB;
      global.GB = function(j) {
        // ...
        if (_GB)_GB(j);
      }
    })()
    

    Since we're never going to have loads of them active it might be the most sensible solution for now.

    However, I do not know how to trigger it.

    Just make sure Gadgetbridge is connected to Bangle.js and you're sorted!

    The problem is, that I have to read what is playing, when I start the app.

    I think the best way to do this is just to send a pause command to gadgetbridge, followed by a play command. That'll cause an update in play state, which will send new data.

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

Get message from Gadgetbridge

Posted by Avatar for Purple-Tentacle @Purple-Tentacle

Actions