How to manual disconnect from BLE UART server #1909
Replies: 11 comments
-
Posted at 2020-06-23 by @gfwilliams That should work absolutely fine: http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_disconnect Although the code you post needs another |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-23 by gerardwr Thanks for your response Gordon. Code changed to:
The response after uploading the code varies with changing the code, here 3 examples:
Not sure what is happening in the background. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-23 by gerardwr Added a “print” when “Quit" is received It seems like the "disconnect" is not executed, output is:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-23 by @gfwilliams
I guess I see |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-23 by gerardwr Ok so BLE task 3 is already in progress should be interpreted as disconnect, right ;-) And the guess that the 1st disconnect is fired, but takes some time to process, so that the 2nd disconnect result in "BLE task 3 ......progress" seems plausible. But I'm not out of the woods yet. When I start the code I get this, as before, disconnects after some "overshoot".
When I re-upload the code for a 2nd time, the UART server recognises the reconnect and starts sending data, but the BangJS does not process the notifications and displays no output, and after 10 secs or so I get an "Uncaught error". My server never gets a disconnect, so keeps sending data, forever.....
My intention was to process the code with a setInterval every minute or so, but with the current behaviour that seems problematic. Hmmmmm, problems, problems. Thanks for your help though, if you have any other suggestions, yes please. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-23 by gerardwr I added a setInterval to process the code ever 10 secs, the behaviour is now like this:
Maybe you know the source of the "uncaught error ........ promise rejection"? Code and selection of output for reference below.
Output like this:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-23 by gerardwr Increase interval from 10 secs to 1 minute, no change in behaviour. Seems that errors are not caused by timing issues. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-24 by @gfwilliams The 'Disconnected' rejection just seems to occur when Espruino disconnects while trying to connect. It might be made worse by the fact it's trying to keep a connection to the PC going as well? All I can suggest is to do an automatic retry, which you could do by adding |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-24 by gerardwr Yes, an automatic retry has crossed my mind, but I wanted to understand why these thing "happed" first. Based on https://www.espruino.com/Puck.js+Controlling+Other+Pucks I made a version with busy/connected flags.
This works brilliant.
Output of 2 subsequent uploads, no errors.
But when I execute the getData function with a setInterval, the "uncaught errors .... promise....." reappear.
I assume that in the subsequent uploads the Espruino environment is fully reset, and the errors do not occur, but using setInterval the environment is not "cleaned" in a similar way. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-24 by @gfwilliams You do seem to be setting:
Which would allow it to try and connect again, even before it had disconnected. Could that be your issue? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-24 by gerardwr No, that's not it. The lines are in the example on your site and I just left them in. To be sure I removed them but it makes no difference. Output with the setInterval:
I think I'm getting close to a "perfect" solution and in hindsite it will be a simple obvious mistake on my part. I catching up my reading om "promises" so at least I'm learning here, that's what it's all about, right!? Appreciate your tireless help! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-06-23 by gerardwr
Hi,
Espruino beginner here, in need for some help.
I am running code from here:
https://www.espruino.com/BLE+UART
The code:

Data is like:
But I would like to disconnect from the server when data “Quit” is received.
Something like:
Have read many things, search the forum, and tried many examples, to no avail.
Who can help along?
Beta Was this translation helpful? Give feedback.
All reactions