Bug? BLE2 Library: Ble disconnected but not really?

ema01

Member
Licensed User
Longtime User
Hi,
i'm developing an app in which i'm communicating with a device using a HM-11 BLE-UART thingy. BLE2 Library 1.38
It's not the first app i'm developing with B4A and BLE, and at this point it's not the only one in which i'm seeing this behaviour, but it's the first in which the issue presents itself very often.

The code (big picture)
i have a set of flags (isConnected,isScanning,hasToDisconnect) used to signal the state of the BLE service and actions to perform.
I have a timer in which i check the various flags and perform actions -> if hasToDisconnect is set, clear it and call BLE.Disconnect

The issue:
BLE is connected, issue disconnect by calling BLE.Disconnect
At BLE_Disconnected sub, clear isScanning flag
At Timer Tick sub, if isScanning=false, set to true, call BLE.StartScan, start Scan Timeout Timer
Scan Timeout Timer Tick, clear isScanning and call BLE.StopScan

But, 1 in 3 times at least the device doesn't come up in the list.
Also, if i switch to a BLE scanner, or search for the device with another phone, the device doesn't come up.
ONLY IF I CLOSE THE APP then the device comes up, as if it wasn't really disconnected.
But i enter in the Disconnected callback so in theory it should be indeed disconnected, right?

This behaviour happens on multiple devices, the issue doesn't come up with iOS/B4i (although i use the same logic)

is there something i'm missing?
 

ema01

Member
Licensed User
Longtime User
Hi erel, thanks for answering.
it happens way less frequently. about 1 in 10 times, instead of 1 in 3.
 
Top