10.2 Tokyo BLE Framework fails to discover devices on Android, works on 10.1 Berlin.

0

I am creating a separate entry for this from replies I made on a similar entry.  This one has to do with the BLE framework and not the BLE component.  Also this has been submitted as RSP-18454

After changing to 10.2, BTLE discovery is not working anymore in Android.  I am using the framework and calling

System.Bluetooth.TBluetoothLEManager.StartDiscovery

It does return TRUE and the OnDiscoveryEnd event does fire, but no devices are found.  I have used the HeartRate sample and it does find the BTLE device, but it is using the BTLE Component, which will be a major change and may not even work.  I am pretty sure I have to use the Framework, since part of my app is in a service and UI is not allowed in a service.

Update 1:On a different computer I have installed 10.1 (update2) and 10.2 (No Hotfix).  No additional options were installed on either one except what was available in the installation menu.  So they are clean installations.  Win32, Win64 and Android were installed.  On the10.1 compiler the BLE project complies, installs and runs, finding all available BLE devices.  Using the exact same project in 10.2, the project complies, installs and runs, except it does not find any BLE devices.  The OnDiscoveryEnd event does fire, but it returns no BLE devices.

Update 2:

I have installed the Toolchain HotFix for 10.2 and it still will NOT discover any BLE devices.  I then installed the 6/23/17 Android patch and still will NOT discover any BLE devices.  Will be filling an issue report in the quality central now.

 
Responses (4)
  • Accepted Answer

    Friday, July 14 2017, 05:06 PM - #Permalink
    0

    Update 6

    it appears that including StartDiscovery in a TThread.CreateAnonymousThread procedure causes the List to be populated, kind of.  After 3-5 repeated calls to StartDiscovery, the list will start to be populated and work.  But it is very inconsistent.  At this point I have an Aug deadline approaching and I have gone back to 10.1 and everything is working again.  If I get time I might come back to this to try and solve it, but it looks like BLE Framework cannot be directly called from the main UI thread.  There was a change in 10.2, whether it is an improvement or a fix for a problem in 10.0/10.1, I dont know, but there was a change in functionality in 10.2

    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, June 28 2017, 10:12 PM - #Permalink
    0

    Projects

    Update 5

    The attached zip file has the project files (.dpr and .dproj), the form file and the main unit. This is a simple app with a memo field and a button. Press the button to scan and the total discovered BLE devices count is shown along with any name that may be advertised.

    For some reason I had to put in the Application.ProcessMessages for 10.1 to fire the DevicesDiscoveryLEEnd event while waiting for the SetEvent to happen. Anyway the performance is still the same, 10.1 finds the BLE devices and 10.2 returns a device count of 0.

    I am wondering if StartDiscovery cannot be called from the main UI thread in 10.2.

    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, June 27 2017, 11:30 PM - #Permalink
    0

    Update 4

    One more finding. I traced the sample heart rate monitor project through to find it eventually uses the same code as the framework. In this case this procedure

    procedure TAndroidBluetoothLEAdapter.DoDiscoveryEnd(const Sender: TObject; const ADeviceList: TBluetoothLEDeviceList);

    from above, ADeviceList returns content the first time and then nil thereafter. The inherited procedure though will use the LastDiscoveredDevice list if ADeviceList is nil. My problem is that this LastDiscoveredDevice list is never populated the first time.

    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, June 27 2017, 11:26 PM - #Permalink
    0

    Update 3

    Some debugging
    For 10.2 in the file System.Android.Bluetooth, this procedure is event that fires after discovery

    procedure TAndroidBluetoothLEAdapter.DoDiscoveryEnd(const Sender: TObject; const ADeviceList: TBluetoothLEDeviceList);
    begin
    DoCancelDiscovery;
    inherited DoDiscoveryEnd(Sender, ADeviceList);
    end;

    ADeviceList is always nil in 10.2 and 10.1 has content.

    I also stepped through this function in the same file
    function TAndroidBluetoothLEAdapter.DoStartDiscovery(Timeout: Cardinal; const FilterUUIDList: TBluetoothUUIDsList; const ABluetoothLEScanFilterList: TBluetoothLEScanFilterList): Boolean;

    The trace steps are identical in 10.1 and 10.2 from what I can see.

    This then leads to this function in the same file

    function TAndroidBluetoothLEAdapter.DoStartDiscoveryRaw(const ABluetoothLEScanFilterList: TBluetoothLEScanFilterList; Refresh: Boolean): Boolean;

    This also traces the same in 10.1 and 10.2, but here there are calls to FJScanner and FJAdapter that I cant seem to trace (no source code). This untraceable code appears to be where the device list is built.

    The reply is currently minimized Show
Your Reply

Please login to post a reply