tinyb icon indicating copy to clipboard operation
tinyb copied to clipboard

stop_discovery() fails

Open MikeHg opened this issue 9 years ago • 1 comments

I tried to run a c++ program that just scans available devices and prints out the manufacturing data. If I run it several times (usually less than 10 times) I finally get an error from the stop_discovery() method:

terminate called after throwing an instance of 'tinyb::BluetoothException' what(): GDBus.Error:org.bluez.Error.Failed: No discovery started

This error only vanishes if I restart the adapter (hciconfig hci0 down/up).

If the error occurs and I check the BluetoothAdapter with another c++ program (get_discovering()) it says still "discovering == true". And if I try then to stop the discovery within the program I'll get the error again.

It might be a timining issue since I can run the hellotinyb program several times without an error. However if I end the hellotinyb program in the code just after discovery, the error occurs as well.

PS: I'm using bluez 5.43 and latest tinyb (0.5.0) and "hcitool lescan" still works even after the error occurs.

MikeHg avatar Nov 05 '16 10:11 MikeHg

Update: I added the following line after the stop_discovering() function call: std::this_thread::sleep_for(std::chrono::seconds(2)); which seems to prevent the problem.

May be without it the program exits before the stop_discovery command has finished, which could leave dbus in a bad state.

I.e. the issue might be an enhancement (adding a delay to the stop_discovery function) or at least an entry should be added to the FAQ / trouble shooting.

MikeHg avatar Nov 06 '16 09:11 MikeHg