• Hey folks! Have been fiddling with the integration aspect of my BangleJS and have been struggling a little bit to figure out what's what. I have been following this:

    https://www.espruino.com/Gadgetbridge

    I installed the bangle version of gadgetbridge on my phone, then installed the android integration on my BangleJS (not 100% sure if this was required for transmit only, but I did it anyway).

    Then I loaded this code into ram in the web IDE:

    Bangle.setUI({mode: "custom", btn: () => {
      Bluetooth.println(JSON.stringify({t:"inf­o",msg:"Hello World"+getTime()}))
      console.log("HELLO");
    }})
    

    disconnected from the web IDE, then connected to GadgetBridge. I then hit the side button on my watch, and saw the little info toast pop up on my phone. Wohoo! Then I hit the button again... Nothing! Strange.

    I hit the button a few more times over the course of about 10 minutes and it seemed to work maybe once or twice more. I proceeded to disconnect from gadgetbridge then reconnect, hit the button again, and it works again - but only once.

    Wonder if anyone with a little more familiarity with these things could weigh in.

    1. Is this unexpected, or am I doing something wrong?
    2. Did I actually need the full android integration app with all the message and message icon dependencies to send info messages to the phone? (It didn't seem to work before I did that, but the integration app only mentions receiving messages, not sending them.)

    My interest right now is just getting the most minimalistic possible setup and get a little bit of hello world data to reliably go both ways, even just to log it to the console.

  • Hi, I just tried your code and it showed up once in the phone when connected to gadgetbridge like you said. However, when checking the log it does show multiple presses. So it does seem to be receiving them from the bangle, just not showing them in Android every time.

    I believe you only need the Android app for getting notifications, music control, find my phone, alarm syncing, battery status syncing, or forwarding your phones gps to the bangle. For Bluetooth print line you shouldn't need it, but I could be wrong.

  • However, when checking the log it does show multiple presses. So it does seem to be receiving them from the bangle, just not showing them in Android every time.

    Thanks for confirming. This is sort of what I suspected. Like maybe android is debouncing them somehow to avoid spamming the end user or something.

    For Bluetooth print line you shouldn't need it, but I could be wrong.

    Yeah that's what I thought but it doesn't seem to work at all if I uninstall the android integration app from the Bangle. Admittedly I am in a little over my head with this right now, but will probably understand it better after learning a bit more about how everything works.

    I agree that simple transmission seems to work without the app on the Bangle side, but gadget bridge doesn't seem to acknowledge them (even once, like when the app is installed). I'm guessing there's something in the integration app that might facilitate that.

  • Oh, I forgot to mention it also handles the navigation messages from Google maps, which after Gordon's latest fixes works fantastic and is a killer feature to have when traveling around.

    And I suppose it's possible the android app is required to establish more than just a simple Bluetooth connection with gadgetbridge.

  • So actually I may have solved my problem entirely, but I'd be happy to hear from people as to why I solved it, because I think I Maxwell Smart'ed / Mr. Magoo'ed my way through it.

    The code I am running now

    Bangle.setUI({mode: "custom", btn: () => {
      Bluetooth.println("");
      Bluetooth.println(JSON.stringify({t:"inf­o",msg:"Hello World"+getTime()}))
      console.log("HELLO");
    }})
    
    function GB(argumentados) {
      g.clear();
      g.drawString(JSON.stringify(argumentados­),0,0,true)
    }
    

    with the android integration uninstalled works PERFECTLY. I noticed that in the android integration there was a random looking Bluetooth.println("") hanging out above the send stuff to gadgetbridge code so I added that to mine, and that made it work. TAH DAH.

    I get the info popup every time on the phone. I get the simulated notifications from GadgetBridge drawn on the screen. It's magnificently simple. I'm very happy.

    Edit: okay it's not EVERY time I press the button that I see the toast message, but it's like 80%. Which is good enough.

  • Glad you got it sorted! Right, I think I know what the problem was then. Gadgetbridge is looking for lines of data sent to it of the form {....}.

    However by default Bangle.js/Espruino has a REPL on the same Bluetooth UART, so it's got a > prompt displayed at the start of the line.

    Normally when you do Bluetooth.println you bypass all that, but because you call console.log("HELLO"); that outputs HELLO plus > on the new line, so next time you send you're sending >{...} which Gadgetbridge ignores.

    Sending a newline before like you're doing solves it :)

    Did I actually need the full android integration app with all the message and message icon dependencies to send info messages to the phone?

    No, but Gadgetbridge sends messages of the form GB({...}) and it complains if there's an error. So it's worth defining function GB() {} to at least stop that error.

    I'd still recommend the Android Integration stuff though as it does do quite a lot for you, including handling HTTP requests.

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

Sending message to Gadgetbridge works only once (ish) every few minutes?

Posted by Avatar for Philip @Philip

Actions