iOS Question Descriptors iBLE?

f0raster0

Well-Known Member
Licensed User
Longtime User
Hi,
What should I add to my code to read the entire list of descriptors?

Example:
service: 181A -> Characteristics: 2A6F, 2A6D -> Descriptors: 2901, 290B, ....




B4X:
Sub Environmental_Sensing(Characteristics As Map)
    For Each id As String In Characteristics.Keys
        'Log(Characteristics.Get(id))
        If id = "2A6F" Then
           ' descriptors¿?

        End If
    
        If id = "2A6D" Then

            ' descriptors¿?
                
        End If
    Next
End Sub

Sub Button12_Click
'-----------------------notiffication state ON ------------------------------------
'    'Environmental_Sensing
'    manager.SetNotify("181A","2A6F",True) 'Humidity
    manager.SetNotify("181A","2A6D",True) 'Pressure


End Sub
 

Attachments

  • gsbl_0401.png
    gsbl_0401.png
    78.8 KB · Views: 240

f0raster0

Well-Known Member
Licensed User
Longtime User
Thanks, I got this error:
Services discovery completed.
UUID: 181A
Error occurred on line: 172 (Main)
Method not found: getService:, target: <CBCentralManager: 0x156cbe10>
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0

B4X:
'//// Environmental - Sensing ////
Sub Environmental_Sensing(Characteristics As Map)  
    For Each id As String In Characteristics.Keys  
        'Log(Characteristics.Get(id))      
        If id = "2A6D" Then         
            Dim no As NativeObject = manager
            Dim service As Object = no.RunMethod("getService:", Array("<service id>")) 'line172
            Dim c As NativeObject = no.RunMethod("getChar::", Array(service, "<characteristic id>"))
            Log(c.GetField("descriptors"))
        End If
    Next   
End Sub

Note: B4i v2.31, iBLE library 2.31
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You need to change <service id> and <characteristic id> with the actual values.
2.
Change the code to:
B4X:
Dim no As NativeObject
no.Initialize("BleManager")
no.SetField("object", manager")
Dim service As Object = no.RunMethod("getService:", Array("<service id>"))
Dim c As NativeObject = no.RunMethod("getChar::", Array(service, "<characteristic id>"))
Log(c.GetField("descriptors"))

I haven't tested it.
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Thanks, I got this error:

[<BleManager 0x186554> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key object.
and if I try again I got:
[<BleManager 0xf5554> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key object.


B4X:
Sub Environmental_Sensing(Characteristics As Map)
    For Each id As String In Characteristics.Keys
        'Log(Characteristics.Get(id))    
        If id = "2A6D" Then       
            Dim no As NativeObject
            no.Initialize("BleManager")
            no.SetField("object", "manager")
            'no.SetField("object", manager)
            Dim service As Object = no.RunMethod("getService:", Array("181A"))
            Dim c As NativeObject = no.RunMethod("getChar::", Array(service, "2A6D"))
            Log(c.GetField("descriptors"))
       End If
    Next 
End Sub
 
Last edited:
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
What does it error mean?

Error occurred on line: 174 (Main)
[<BleManager 0xbc780> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key object.

line 174 in code above:
no.SetField("object", "manager")
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be:
B4X:
Dim no As NativeObject
no = no.Initialize("BleManager").RunMethod("new", Null)
no.SetField("object", manager)
Dim service As Object = no.RunMethod("getService:", Array("<service id>"))
Dim c As NativeObject = no.RunMethod("getChar::", Array(service, "<characteristic id>"))
Log(c.GetField("descriptors"))
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Thanks Erel, I couldn't read anything.. the result is: null
not sure why.. at the moment I had tried with all the services that I'm reading but always the result is: null
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Update to iBLE v1.40: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.48179/page-3

You can then run this code:
B4X:
'discover the descriptors
Dim per As NativeObject = manager.GetPeripheralObject
per.RunMethod("discoverDescriptorsForCharacteristic:", Array(manager.GetCharacteristicObject(<service id>, <char id>))
After a few seconds you can check the descriptors:
B4X:
Dim c As NativeObject = manager.GetCharacteristicObject(...)
Log(c.GetField("descriptors"))
 
Upvote 0
Top