BLE device disconnects after sometime - python-3.x

I am using two BLE devices for connection to establish using bgapi library. After sometime both devices disconnect abruptly at the same time. I don't know where to look into as I can't see any errors that is logged.
Connection for one device is working fine but issue is with the connecting two devices.
Most importantly it is not happening every time.(Out of five tries devices are disconnecting once)
I tried udev blacklist. I thought modem manager might be interfering but of no use.

Related

Windows 10 IoT and Adafruit M0 BLE comminication [duplicate]

I got an issue with reconnection to my BLE device.
Senario that works
- BLE Device is not paired
- Pi boots and start my App, find's the BLE device, pair and connect, receiving data
- Boot Pi and start my App, it will not pair as its already paired, it connects fine and receiving data.
Senario that does not work
- BLE Device is not pair or pair, does not matter
- If my BLE device disconnect due to power loss or out of range and gets powered up or back in range the Pi will reconnect and throw:
'System.Exception' in mscorlib.ni.dll
There is no user session key for the specified logon session. (Exception from HRESULT: 0x80070572)
If I try to reboot the Pi, the same message is thrown when I try to execute: await _readCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
The only thing that works is if I unpair the device every time it disconnect.
This is the same issue that this guy has: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b98d77f2-bf5e-45fc-9495-1c444b54450e/uwpreconnecting-to-a-ble-csac-device-causes-exception?forum=wpdevelop
Maybe there is anyone here that has seen the same issue and solved it ?
Thanks
The reason for this particular error you are receiving is almost certainly that the BLE device itself is not storing the bonding information that is negotiated during the pairing process. For an existing BLE pairing to be re-used, the device must retain the bonding with its partner for future communication sessions.
Developers can sometimes work around this device shortcoming in their (non-Windows) PC or phone application by having the PC or Mobile app delete any previous pairings with the device already retained, and negotiate a new pairing each time it sees the Bluetooth device. This is possible because many Bluetooth devices have a static PIN, require no interaction for pairing, and remain in open pairing mode. So the app creates a new device pairing upon each communication. The Mac BLE API requires no user interaction for pairing and un-pairing as well.
But this solution is unworkable under Windows BLE API, because unlike regular Bluetooth, the Bluetooth Low Energy API requires user interaction during both the pairing, and un-pairing "ceremonies". The user must agree to every pairing, and must agree to every un-pairing. This makes this workaround solution a non-starter from a UX standpoint on Windows. My guess is the BLE device manufacturer isn't storing the bonding.
We ran into such a situation ourselves developing our own BLE driver to speak with our own BLE board; we had to re-do the firmware running our BLE device because while it would work under Mac OS and Android with the method described above, the BLE API available on the Microsoft UWP requires user interaction during the pairing ceremony. This seems the right way to do things, anyway.

Windows 10 IoT Bluetooth LE

I got an issue with reconnection to my BLE device.
Senario that works
- BLE Device is not paired
- Pi boots and start my App, find's the BLE device, pair and connect, receiving data
- Boot Pi and start my App, it will not pair as its already paired, it connects fine and receiving data.
Senario that does not work
- BLE Device is not pair or pair, does not matter
- If my BLE device disconnect due to power loss or out of range and gets powered up or back in range the Pi will reconnect and throw:
'System.Exception' in mscorlib.ni.dll
There is no user session key for the specified logon session. (Exception from HRESULT: 0x80070572)
If I try to reboot the Pi, the same message is thrown when I try to execute: await _readCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
The only thing that works is if I unpair the device every time it disconnect.
This is the same issue that this guy has: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b98d77f2-bf5e-45fc-9495-1c444b54450e/uwpreconnecting-to-a-ble-csac-device-causes-exception?forum=wpdevelop
Maybe there is anyone here that has seen the same issue and solved it ?
Thanks
The reason for this particular error you are receiving is almost certainly that the BLE device itself is not storing the bonding information that is negotiated during the pairing process. For an existing BLE pairing to be re-used, the device must retain the bonding with its partner for future communication sessions.
Developers can sometimes work around this device shortcoming in their (non-Windows) PC or phone application by having the PC or Mobile app delete any previous pairings with the device already retained, and negotiate a new pairing each time it sees the Bluetooth device. This is possible because many Bluetooth devices have a static PIN, require no interaction for pairing, and remain in open pairing mode. So the app creates a new device pairing upon each communication. The Mac BLE API requires no user interaction for pairing and un-pairing as well.
But this solution is unworkable under Windows BLE API, because unlike regular Bluetooth, the Bluetooth Low Energy API requires user interaction during both the pairing, and un-pairing "ceremonies". The user must agree to every pairing, and must agree to every un-pairing. This makes this workaround solution a non-starter from a UX standpoint on Windows. My guess is the BLE device manufacturer isn't storing the bonding.
We ran into such a situation ourselves developing our own BLE driver to speak with our own BLE board; we had to re-do the firmware running our BLE device because while it would work under Mac OS and Android with the method described above, the BLE API available on the Microsoft UWP requires user interaction during the pairing ceremony. This seems the right way to do things, anyway.

Bluez auto reconnect devices

I am writing a library in C/C++ for a Bluetooth low energy device. So far I have been using the D-Bus interface exposed by Bluez and been able to discover, connect and communicate with the device.
However, when the device disconnects either due to a link failure or it being out of range, reconnecting to it is not trivial. Ideally I would like to be able to create pending connections to all disconnected devices, but Bluez doesn't seem to support that. It seems that Bluez only supports one simultaneous connect call, which timeouts after 15-20 seconds.
A solution would thus be to listen for advertisement packages, and connect when a known device is detected. The good people on #bluez told me that this was already implemented, and the way to do it is to register an object that implements GattProfile1 with the GattManager1 RegisterProfile method. Trying this gave no result, the device stays disconnected after a link failure. It is also very poorly documented, so there is a good chance I have missed something.
My questions are: Is this the right solution? Will it provide a seamless and fast reconnections? If it is, what can be wrong?
If you wish to reconnect to a single bluetooth device, you can monitor the connection state by receiving org.freedesktop.DBus.Properties.PropertiesChanged, and calling org.bluez.Device1.Connect to reconnect when necessary. Since this will timeout, you can put Connect() inside a loop which you will exit only when the org.bluez.Device1.Connected property is true.
Has the original author managed to do this yet for multiple devices by implementing GattProfile1?

Automatic bluetooth connection to a certain device

I am working on an application (windows phone 8.1), which is the following: if my phone is already connected to a bluetooth device then it should connect in parralel to another device which is already paired("cc2541"). I would appreciate a little help with the coding.
My problem is i don't know how to connect to a device automatically. I only found code samples that are only scans and lists devices and it only connects when I touch the screen ( approve the connectivity ).
You can get the RSSI value (signal strength) for each device, then you can implement a dispatcherTimer, where you start the scanning as the timer starts and then connect to the closest device on a timeout.
This is a basic example of automatic connection establishment.

Bluetooth connection close itself right after start

my problem is the connection with a Bluetooth device. I have a Netbook with an integrated bluetooth device. I want to connect my netbook with an OBD-II interface and write a software to read out the stats of my car. To test the connection, I started by adding the OBD device via the bluetooth menu. The manager connects to the interface and it wants me to wait while the configurations are taking place. This state lasts "forever". After 60-Minutes of waiting, I closed the window. However, the device is shown in the list of available devices. Because I'm not able to switch the button to initiate the connection, I thought about using minicom (the OBD-II interface uses SPP for communicating).
As far as I did understand, I need an initiated connection with a bluetooth device and with it a virtual serial port to connect to with minicom. After reading some postings, I found out that the hcitool should be able to create the bluetooth session. With this I was able to connect to the device and the "connected" button turned on. Unfortunately it switches back after 2 secs.
hcitool scan is able to find the device
hcitool cc 00:11:22:33:44:55 is able to connect for the already mentioned 2 secs
hcitool con list the connection if it's called within 2 sec after initiating
I also tried to connect via a Windows PC using putty. Windows connected with the device without a problem and after that, I was able to send requests and get the appropriate answers. So it seems like the interface is working correctly.
I'm using Fedora 17 with gnome3. If you need any output or more information, please let me know.
Thanks in advance

Resources