BLE: unexplained delay while WriteCharacteristic (XE8)

0

Hello, 

 

in an App for Andriod an iOS i use TBluetoothLEManager to communicate between mobile and a BLE-Device. 

To send data to the BLE-device, i use the code-sequence:       

 

CR_GattService:=FBLEDevice.GetService(CR_SERVICE);

CR_GattCharact:=CR_GattService.GetCharacteristic(CR_CHARACTERISTIC);  

CR_GattCharact.SetValue(sOutBuffer);   

sTime:=Now;    

TabbedForm.mDevOut.Lines.Add(SecondOf(sTime).ToString');

FBLEDevice.WriteCharacteristic(CR_GattCharact); 

sTime:=Now;    

TabbedForm.mDevOut.Lines.Add(SecondOf(sTime).ToString'); 

 

 

If I send a single command to the BLE-Device, the time between CR_GattCharact.

SetValue and FBLEDevice.WriteCharacteristic is about 200ms.  

When I send two command on behind the other, the time to write chracteristics is 3s?? 

 

Has anybody an explanation for that?(Android 4.4.2, on iOS this delay do not exist)  

 

Best Markus

Responses (4)
  • Accepted Answer

    Monday, May 14 2018, 08:23 AM - #Permalink
    0

    Hi RadXEGeek63!

    I don't understand why this doesn't get fixed, but if you want things to work you need to edit System.Android.Bluetooth.pas (you can simply make a copy of the source file ..\source\rtl\net\System.Android.Bluetooth.pas and put it in your project directory) and change the order of the lines:

    FGatt.DoOnCharacteristicWrite(LGattChar, TBluetoothGattStatus(status));

    and

    FGatt.FCallbackGattEvents.SetEvent;

    in procedure TAndroidBluetoothGattListener.onCharacteristicWrite(gatt: JBluetoothGatt; characteristic: JBluetoothGattCharacteristic; status: Integer);

    Good luck,

    Per M

    The reply is currently minimized Show
  • Accepted Answer

    Monday, May 07 2018, 08:14 AM - #Permalink
    0

    Hi guys,

     

    I see the same problem with Android (7.1.1).  I do not see a delay when I run my app on an iOS system.  

    The reply is currently minimized Show
  • Accepted Answer

    Friday, December 02 2016, 10:22 AM - #Permalink
    0

    Hi!

    My experience when writing a multi-platform BLE Central is identical as OP's, with various Android devices running Android 5.1, 6.0, and 7.0 using SDK 23 and 25. The delay I observe is, however, 5 sec, which seems related to the 5000 msec CallbackGattTimeout in TAndroidBluetoothLEDevice.DoWriteCharacteristic.

    With my limited understanding of BLE I don't understand the reason for the WaitFor in the Android-specific code as I can simply choose to wait for the the OnCharacteristicWrite of TBluetoothLEDevice.

    On the other hand, I cannot see how this would be an error in the Android code as it would make RAD Studio a fairly useless tool for writing an Android app that communicates with BLE Peripherals.

    What must be done to get this to work properly?

    Best regards,

    Per M

    The reply is currently minimized Show
  • Accepted Answer

    Monday, October 26 2015, 01:47 PM - #Permalink
    0

    Is the delay different on a different version of Android? You could try tracing down into the call to write and see where the delay takes place. 

    The reply is currently minimized Show
Your Reply

Please login to post a reply.........