jasongin / noble-uwp

Noble (Node.js Bluetooth LE) with Windows 10 UWP bindings
MIT License
83 stars 45 forks source link

no disconnect on device hard shutdown #43

Open farfromrefug opened 6 years ago

farfromrefug commented 6 years ago

I have a device running using bleno on Pi/Edison I use noble-uwp on windows and noble on Mac/Linux. I recently found an issue with noble-uwp.

If i shut down my bleno app genlty, which calls disconnect, the noble-uwp client gets the disconnect event. And i see nothing in the debug console (with DEBUG=*) Now if i hard shutdown my bleno device, the noble-uwp client still think it's connected. Noble on mac/linux does get the event.

I think it should be very easy to reproduce with a bleno/noble-uwp setup

I am not where this might come from. There is also a heartbeat on windows? I mean does BLE on Windows regularly "ping" the connected devices? If so it should see that the device is not there anymore. Maybe it s a timeout duration issue I will investigate that but as you know windows bluetooth a lot better than i do, i think you could understand it better.

NAllred91 commented 6 years ago

I think I may have been able to get around this by periodically reading from a characteristic.

I'm not sure if there is a better work around, but this is the best I've come up with for the moment.

setInterval(() => {
        char.read((err, value) => {
            // I never get an error...
            if(err) peripheral.disconnect()
            // But when the peripheral is disconnected, the value is an error object with a message..
            if(value.message) peripheral.disconnect()
         })
}, 1000)