• Hi (help !),
    I am struggling to make the BangleJS automatically reconnect to my BLE browser (on my iPhone or on my Raspberry-Pi).
    Initial connection is good but when I move the watch out of BLE range and then move it back again I would like it to reconnect automatically.

    I have tried adding the following to my copy of UART.js:-

    device.addEventListener('gattserverdisco­nnected', function disconnected() {
                setTimeout(reconnect,180000);
                function reconnect()
                {device.gatt.connect();}});
    

    The event fires and the browser displays a bluetooth icon as though it is connected but I seem to have lost the UART object because data transfers will not work afterwards.
    If anyone has any ideas I would be very grateful !
    Thanks very much :-)
    Mark

  • There is a lot to do after doing device.gatt.connect()
    see everything below this https://github.com/espruino/EspruinoWebT­ools/blob/master/uart.js#L209

  • Thanks for your reply, I can see what you mean, there is a lot to do to the connection.
    I'm hoping to find a quick way of reconnecting to the previous connection but if not then I can hopefully do it the long way.
    Thanks :-)

  • Sorry, it looks like that's not implemented in UART.js, however you could look at using the Puck.js library which is very similar.

    In it there is a connection.reconnect method which should do what you need:
    https://github.com/espruino/EspruinoWebT­ools/blob/master/puck.js#L236

    So you may not even have to change the file, you can do connection = Puck.connect() to get the connection, then connection.device.addEventListener... and connection.reconnect()

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

Help Required To Automatically Reconnect to BLE Browser

Posted by Avatar for user156292 @user156292

Actions