• Hi,

    I installed Espruino Hub on my RPi, and loaded the example code (added a setInterval) from https://www.espruino.com/BLE+HTTP+Proxy on my Bangle.

    response="";
    
    setInterval(function () {
    
    print("connecting");
      
    NRF.requestDevice({ filters: [{ services: ['1823'] }] }).then(function(device) {
      require("ble_http").httpRequest(device, "pur3.co.uk/hello.txt", function(d) {
        response=JSON.stringify(d);
        print(response);
      });
    });
    
    }, 10000);
    

    Sometimes the Bangle gets the expected response from the Hub, sometimes I get error Uncaught Error: Unhandled promise rejection: Disconnected.

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v06 (c) 2019 G.Williams
    >
    WARNING: Softdevice error BLE error 0x11 (BUSY) (bluetooth.c:818)
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnected
    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnected
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Got service
    WARNING: Softdevice error BLE error 0x11 (BUSY) (bluetooth.c:818)
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnected
    WARNING: Softdevice error BLE error 0x11 (BUSY) (bluetooth.c:818)
    

    I got similar errors when I used my own code in the Bangle and a self-coded BLE server on my Esp32 (ref http://forum.espruino.com/conversations/­349804/#comment15369436);

    Could this be caused be an "issue" in the BLE handling of Espruino, or is it unreliability in the BLE protocol?

  • What's the unexpected response you're getting?

    // This is a DataView, but:
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    // Converting it to a String gives:
    var dv  = {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13};
    print(E.toString(dv.buffer))
    // Hello World!
    

    Could the Softdevice error BLE error 0x11 (BUSY) error be because you might have been trying to connect when a device was already in the process of connecting? That does seem a bit strange.

    But in general you would expect the connection to fail sometimes, especially as you'll be connected to Bangle.js via Bluetooth already so it's trying to juggle connecting, but also doing communications with the host PC at the maximum datarate it can handle.

    Also Bangle.js's bluetooth range isn't actually that great, so I guess that could cause you issues as well.

    I'd be interested to know whether it's actually any more reliable when you're not connected by PC, or if you run NRF.setConnectionInterval(100) to force bangle.js to use a lower-datarate connection to the PC (the default is NRF.setConnectionInterval(7.5))

  • The contents of "buffer" was expected, so apologies that I have mislead you with my post.

    When tested:

    • the Bangle was connected to the WebIde to monitor the response from the EspruinoHub, I understand that might require "juggling" when connecting to the Hub as well.
    • No other devices were connecting to the HUB.
    • distance between Raspberry/Hub and Bangle was 30 cm.
    • based on previous experience I was not surprised about the scarce connection errors, was expecting them. Will do some testing withe the connectionInterval later.

    The error that bugs me the most is Uncaught Error: Unhandled promise rejection: Disconnected.

    Because I had this error many times too when I coded my own BLE-UART-client on Bangle i.c.w. my own coded BLE-peripheral-server on an ESP32 (ref. in my post above). Thought it was due to my inexperience with Espruino and BLE.

    Now I'm using your code on Bangle and on Raspberry the same error appears, that gives me a little more confidence in my own coding skills ;-)
    Thought that reporting it here would give you some inspiration on the cause of this error.

  • Ok, so I added setConnectionInterval in the code, but I do not see a major difference.

    response="";
    NRF.setConnectionInterval(100);
    
    setInterval(function () {
    print("connecting");
      
      
    NRF.requestDevice({ filters: [{ services: ['1823'] }] }).then(function(device) {
      require("ble_http").httpRequest(device, "pur3.co.uk/hello.txt", function(d) {
        response=JSON.stringify(d);
        print(response);
      });
    });
    }, 10000);
    

    Selection from output

    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnected
    WARNING: Softdevice error BLE error 0x11 (BUSY) (bluetooth.c:818)
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Uncaught Error: Unhandled promise rejection: No device found matching filters
    connecting
    Uncaught Error: Unhandled promise rejection: No device found matching filters
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnected
    WARNING: Softdevice error BLE error 0x11 (BUSY) (bluetooth.c:818)
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Got service
    Got characteristic
    Set URI
    Got characteristic
    Written GET
    Disconnected
    {"buffer":[72,101,108,108,111,32,87,111,­114,108,100,33,10],"byteOffset":0,"byteL­ength":13}
    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnected
    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnected
    connecting
    Connected
    Uncaught Error: Unhandled promise rejection: Disconnec
    

    The dreaded "Unhandled promise rejection ..." is still prominently present, with a scarce "BLE busy..".

  • Uncaught Error: Unhandled promise rejection: Disconnected

    Yes, what that means is the Bluetooth link got terminated while Espruino was waiting for something else to finish (getting characteristics/etc).

    The disconnect is coming from a pretty low level in the Bluetooth stack, so I'm pretty confident it's not some bug in Espruino itself that causes the disconnect. I guess it's possible some setting could be tweaked to make the connection more error tolerant, but I'm afraid I am yet to find anything that it seems would help.

  • Ok, thanks. Now I know at least that I did not cause the error in my own code.

    My knowledge about BLE is rather scarce, so I'm afraid that I can't help you there.

    But I'm good at testing, so if you need my help at some point ........

  • As an intermezzo I tried the Bangle.js App Loader from https://github.com/espruino/BangleApps.

    Wanted to use it as a "simple" file uploader, but so far I can see the current code does not support that.

    As an experiment I copied the cmdInstallApp function, slashed it, and created:

    function cmdUploadFile(fileName, deviceAddress) {
        bangleSend(fileName, deviceAddress).then(() => process.exit(0));
    }
    

    When I executed it I got the dreaded 'Unhandled Prmise Rejection`, there's no escaping it ;-)

    iMac19-9:bin gerard$ node apploadergwr.js upload heartOnScreen.js f3-2c-dc-06-01-95
    Initialising Notifications
    <snip>
    UART: Discovering...
    UART: Found device:  f3-2c-dc-06-01-95 Bangle.js 0195
    UART: Connecting to f3-2c-dc-06-01-95
    UART: BT> Connecting
    UART: BT> Connected
    UART: Disconnected
    (node:79575) UnhandledPromiseRejectionWarning: Disconnected but not complete
    (node:79575) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unha­ndled_rejections_mode). (rejection id: 1)
    (node:79575) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    

    Not sure if this error message is interesting for you, but here it is.

  • Hmm - so those Promise rejections are coming from the PC, not the Bangle :)

    If it happens all the time I'd guess maybe it's something in the code you're uploading that causes the Bangle to drop the connection?

  • Yes, in this case it seems it's coming from node coming from the Espruino Hub on Arduino.

    But it's not PC-only, as my selfcoded BLE-peripheral on an ESP32 has the unhandled promise.... too :-(

    And the Bangle code from post #4 has no "code" at all, it's just a httprequest, so thta's not it either.

    BTW Espruino code on a bare NRF52832 (version 1V97) i.c.w. the Espruino Hub also has the same error.

    Beats me!

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

Espruino Hub installed OK, but Bangle connect fails often

Posted by Avatar for gerardwr @gerardwr

Actions