-
• #2
Wed 2021.09.08
Hi @Jeff One idea might be to have the Puck regularly signal the web page, and have the web page continually look for that 'ping'. Within a try/catch block, when the ping doesn't arrive timely, throw and trap an exception within the web page itself.
Example bi-directional comm examples here:
https://www.espruino.com/Web%20Bluetooth
https://www.puck-js.com/go -
• #3
Thanks for the information Robin. I will look into a try/catch block.
Rather than looking for an error is could I query the BLE and make use of the following information the puck sends?
Sorry if this is total newby question.
puck.js:406 Connected
puck.js:406 SEND ERROR: NotSupportedError: GATT operation failed for unknown reason.
puck.js:406 Disconnected (gattserverdisconnected) -
• #4
Sun 2021.09.12
Hi @Jeff as I indicated 'One idea might be to have the Puck regularly signal' and you now have yet another.
I steered away from that solution as I wasn't able to find a suitable example/tutorial and there had been a recent post on how to wire the rejected 'Promise' into existing code.
http://forum.espruino.com/conversations/367683/
http://www.espruino.com/Reference#BluetoothRemoteGATTService
Anyone suggest/provide a simple example code block, other than the API reference?
-
• #5
Hi - those errors actually come from the
puck.js
library on the PC.I think the easiest way to check for connection is to use
Puck.isConnected()
. I believePuck.getConnection().on('close', function() { console.log("connection closed!") });
will work too - but to need to do that after you connected the first timeThe Puck library isn't that well documented externally, but there are a bunch of comments inside it that might help: https://github.com/espruino/EspruinoWebTools/blob/master/puck.js#L446
Hello all,
I am a newbie and appreciate any help. I have tried generating a solution but have lost much hair trying!
I connect to the puck from a Windows browser using the following javascript function and query the accelerometer with a timer using the subsequent function. How can I detect if the puck.js disconnects?
Thanks in advance,
Jeff