iOS Question How can I read the BLE Characteristic properties?

Discussion in 'iOS Questions' started by Turbo3, Dec 17, 2015.

  1. Turbo3

    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.

    Code:
    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
    };
     
  2. Erel

    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:
    Code:
    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
     
  3. Turbo3

    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: Dec 17, 2015
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice