Bangle.http() when in WebIDE

Posted on
  • Hi,

    I just got a Bangle.js 2 for Christmas. I'm excitedly tinkering with it and enjoying it so far! One pain point I've run into is that Bangle.http() doesn't work (always times out) when connected to the WebIDE, since that function uses Gadgetbridge to make the actual request. This makes it a rather clunky process to develop code that uses that function - I have to make the changes in WebIDE, upload it to Bangle, disconnect the IDE, connect to Gadgetbridge, wait for GB to be ready for http requests, and then hope it works correctly because debugging will be difficult if it doesn't. 😅 Would it be possible to make the WebIDE recognize and answer (some subset of) GB commands from Bangle?

  • Did you consider using this relay? https://forum.espruino.com/conversations­/381841/

  • That works, thanks! The relay is a little slow, but I am able to make http requests from the IDE now.

    I had to connect in this specific order, in case that helps anyone else:

    1. Disconnect from the watch in Gadgetbridge (but leave Bluetooth on in the phone settings).
    2. Open Edge on my phone and go to https://www.espruino.com/ide/relay/
    3. Connect the relay to the watch.
    4. Open the IDE on my desktop.
    5. Enter the relay key (shown on the relay console) in the Relay Key field in the desktop IDE. At this point I can enter commands in the REPL (with an unfortunate amount of lag) and they run on the watch.
    6. On the phone, switch back to Gadgetbridge and connect to the watch again.

    (I couldn't connect the relay to the watch without first disconnecting the watch from Gadgetbridge, presumably because the watch isn't in "pairing" mode when it is connected to Gadgetbridge.)

    Some downsides:

    There is a lot of console noise in the desktop IDE, presumably from Gadgetbridge doing too much for the watch to handle (I see FIFO_FULL errors pretty frequently when connecting/disconnecting to Gadgetbridge).

    Also, if the relay disconnects (such as if my phone goes to sleep), then I have to start all over. 🙁

    Another solution I found that I might try (at least while developing) is checking the connected Bluetooth address using NRF.getSecurityStatus().connected_addr and mocking out the http call if it's not my phone's address. (It would be really nice if I could just call some magical Bangle.isGadgetbridgeConnected() method, but I haven't found anything like that.)

  • Glad you got something working!

    I've been considering adding the Relay capability into the App Loader itself, which could then be run from within Gadgetbridge and would avoid a lot of this messing around I think?

    There is a lot of console noise in the desktop IDE, presumably from Gadgetbridge doing too much for the watch to handle

    End of last year I got flow control into Gadgetbridge, so while it's not in the play store version, nightlies, or the next Play Store release should have the FIFO_FULL fixed.

    Another solution I found

    You could also fork the Web IDE yourself: https://github.com/espruino/EspruinoWebI­DE

    Then I think it might be possible to modify the emulator code quite easily look at the data that is sent from the emulated Bangle (https://github.com/espruino/EspruinoWebI­DE/blob/master/emu/common.js#L187) and implement the HTTP request yourself?

    However when running in a browser you're limited by CORS

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

Bangle.http() when in WebIDE

Posted by Avatar for drmercer @drmercer

Actions