sputnikdev / bluetooth-manager

Java Bluetooth Manager. A library/framework for managing bluetooth adapters, bluetooth devices, GATT services and characteristics
Apache License 2.0
95 stars 22 forks source link

Bluegiga Connection times out after a few seconds #15

Open Vita-Innovations opened 4 years ago

Vita-Innovations commented 4 years ago

Hi! Thank you first of all for being the only option out there to implement Java bluetooth development on a Windows machine.

I've made an SPO2 continuous monitoring software using your asynchronous heart rate monitor. I use a Bluegiga BLE112 dongle that connects via bluetooth to an Arduino connected to a pulse oximeter. However, once a connection has been established and a few seconds of data has been received by the software, it stops, and after ten or so seconds, we get these warnings:

18:21:56.079 WARN Disconnection event received bluegiga:/88:6B:0F:C9:CA:59/F7:FA:FA:D5:1E:9C. Reason: CONNECTION_TIMEOUT. 18:22:07.084 WARN Timeout received while calling complex procedure: BlueGigaFindInformationFoundEvent / BlueGigaProcedureCompletedEvent. Trying one more time 18:22:07.087 WARN Could not discover device attributes: bluegiga:/88:6B:0F:C9:CA:59/F7:FA:FA:D5:1E:9C org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaProcedureException: Could not initiate process: BlueGigaFindInformationFoundEvent / BlueGigaProcedureCompletedEvent / WRONG_STATE at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaHandler.callProcedure(BluegigaHandler.java:476) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaHandler.syncCallProcedure(BluegigaHandler.java:411) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaHandler.getCharacteristics(BluegigaHandler.java:213) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaDevice.discoverCharacteristics(BluegigaDevice.java:505) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaDevice.lambda$discoverAttributes$2(BluegigaDevice.java:435) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaHandler.runInSynchronizedContext(BluegigaHandler.java:190) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaDevice.discoverAttributes(BluegigaDevice.java:428) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaDevice.handleConnectionStatusEvent(BluegigaDevice.java:478) at org.sputnikdev.bluetooth.manager.transport.bluegiga.BluegigaDevice.bluegigaEventReceived(BluegigaDevice.java:283) at com.zsmartsystems.bluetooth.bluegiga.BlueGigaSerialHandler$2.run(BlueGigaSerialHandler.java:471) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:844) 18:22:12.108 WARN Could not discover device attributes: bluegiga:/88:6B:0F:C9:CA:59/F7:FA:FA:D5:1E:9C

On top of setting that characteristic governors and listeners as you did in your example, the only extra thing I do is check for connectivity by getting a device governor and returning isReady(). Is this an issue with your library or how I am implementing it? If not, is there a way for me to reset the connection to the arduino and reconnect once I have detected there to be a timeout? Also, is there a way for me to set my own timeout length so that the software reacts faster to an event such as this?