iOS Question How can I read the BLE Characteristic properties?

Turbo3

Active Member
Licensed User
I need to know if a characteristic is readable, writable or support notify. Here is a table of the bit significant property bits. I just need a way to read the characteristic properties added to the iBLE library or some inline code that can return the properties.

Inputs would be the Service and Characteristic and the return would be an integer holding the corresponding property bits.

B4X:
typedef NS_ENUM(NSInteger, CBCharacteristicProperties) {
    CBCharacteristicPropertyBroadcast                                               = 0x01,
    CBCharacteristicPropertyRead                                                    = 0x02,
    CBCharacteristicPropertyWriteWithoutResponse                                    = 0x04,
    CBCharacteristicPropertyWrite                                                   = 0x08,
    CBCharacteristicPropertyNotify                                                  = 0x10,
    CBCharacteristicPropertyIndicate                                                = 0x20,
    CBCharacteristicPropertyAuthenticatedSignedWrites                               = 0x40,
    CBCharacteristicPropertyExtendedProperties                                      = 0x80,
    CBCharacteristicPropertyNotifyEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0)     = 0x100,
    CBCharacteristicPropertyIndicateEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0)   = 0x200
};
 

Erel

Administrator
Staff member
Licensed User
Update to v1.31: http://www.b4x.com/android/forum/threads/updates-to-internal-libraries.48179/page-3#post-387727

Now you can find the supported properties with this code:
B4X:
Sub ble_DataAvailable (Service As String, Characteristics As Map)
   For Each c As String In Characteristics.Keys
     PrintCharProperties(c, ble.GetCharacteristicProperties(Service, c))
   Next
End Sub

Sub PrintCharProperties(Characteristic As String, Properties As Int)
   Log($"${Characteristic} Properties:"$)
   Dim props As Map = CreateMap(1: "Broadcast", 2: "Read", 4: "WriteWithoutResponse", 8: "Write", _
     0x10: "Notify")
   For Each key As Int In props.Keys
     If Bit.And(Properties, key) <> 0 Then Log(props.Get(key))
   Next
End Sub
 

Turbo3

Active Member
Licensed User
Erel, Perfect. Works great!!! Thank you so much.

My app can now handle 3 different brands of Bluetooth LE adapters by automatically determining which Characteristic handles Notify and which handles Writes. I have a fourth adapter coming in a few days and with this code I should just need to add the device name to make it work.
 
Last edited:
Top