iOS Question iBLE error ReadData Service

Moroz

Member
Licensed User
Good afternoon, there was a problem with the work of the library iBLE
When reading the characteristics, an error occurs.

Application_start
Application_Active
Found: DexcomW7, D2B289C7-6B84-990A-1D79-6553F0BBDB6D, RSSI = -56, (read only map) {
kCBAdvDataIsConnectable = 1;
kCBAdvDataLocalName = DexcomW7;
kCBAdvDataManufacturerData = <d0004603>;
kCBAdvDataServiceUUIDs = (
FEBC
);
}
end
Discovering services
Services discovery completed.
<B4IList: (
"F8083532-849E-531C-C594-30F1F86A4EA5",
180A
)>
Disconnected: <B4IExceptionWrapper: Error Domain = CBErrorDomain Code = 7 "The specified device has disconnected from us." UserInfo = {NSLocalizedDescription = The specified device has disconnected from us.}>

Tell me where to look for the cause?
Used your example BLE Example
 

Erel

Administrator
Staff member
Licensed User
Based on the error message, the connection has broken. Maybe it doesn't support reading its characteristics.
 

Moroz

Member
Licensed User
B4X:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
    FPANE_Log([NSString stringWithFormat:@"spiketrace ANE G5BLEManager.m in didDiscoverCharacteristicsForService, discovered characteristics"]);
    if (error) {
        FPANE_Log([NSString stringWithFormat:@"spiketrace ANE G5BLEManager.m error Discovered characteristics for %@ with error: %@", service.UUID, [error localizedDescription]]);
        return;
    }
  
    for (CBCharacteristic *characteristic in service.characteristics){
        if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:G5_MM_WRITE_CHARACTER_UUID]]) {
            FPANE_Log([NSString stringWithFormat:@"spiketrace ANE G5BLEManager.m in didDiscoverCharacteristicsForService, found writeCharacteristic"]);
            self.writeCharacteristic = characteristic;
        }
        if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:G5_MM_NOTIFY_CHARACTER_UUID]]) {
            FPANE_Log([NSString stringWithFormat:@"spiketrace ANE G5BLEManager.m in didDiscoverCharacteristicsForService, found notifyCharacteristic"]);
            self.notifyCharacteristic = characteristic;
            [peripheral setNotifyValue:YES forCharacteristic:characteristic];
        }
    }
}
This is a piece of code from Spike here you can clearly see what the characteristics are reading
 

Erel

Administrator
Staff member
Licensed User
It doesn't read anything. Just register for notifications. You should do the same.
 

Moroz

Member
Licensed User
Sorry for the trouble, how can I do this with the help of iBLE? Spike application no longer works on ios, and my daughter has diabetes. I urgently need to make an application to read data from dexcom g6.
 

Erel

Administrator
Staff member
Licensed User
Does the connection break when you call ReadData? Maybe you are trying to read from the wrong service.
 

Moroz

Member
Licensed User
B4X:
Services discovery completed.
<B4IList: (
"F8083532-849E-531C-C594-30F1F86A4EA5",
180A
)>
I readdata from this service: "F8083532-849E-531C-C594-30F1F86A4EA5"
this service in list BLEManager.
 

Moroz

Member
Licensed User
B4X:
#define G5_MM_SERVICE_UUID                            @"F8083532-849E-531C-C594-30F1F86A4EA5" - this Service
#define G5_MM_WRITE_CHARACTER_UUID            @"F8083534-849E-531C-C594-30F1F86A4EA5" - this characteristic write
#define G5_MM_NOTIFY_CHARACTER_UUID           @"F8083535-849E-531C-C594-30F1F86A4EA5" - this characteristic notify
#define G5_MM_ADVERTISEMENT_UUID                @"0000FEBC-0000-1000-8000-00805F9B34FB"


At the stage of reading data from the service, nothing happens.
As you can see here 2 services:
"F8083532-849E-531C-C594-30F1F86A4EA5",
180A
If you read the second, it gives information about the device.
And if you read in order, then the reading of the first does not happen and does not even reach the second.

B4X:
For Each s As String In ConnectedServices
   manager.ReadData(s)
Next
 

Erel

Administrator
Staff member
Licensed User
Only read the first one. Then wait for the DataAvailable event.
 

Moroz

Member
Licensed User
B4X:
Application_Start
Application_Active
Time: 15:06:01; Connect: DexcomW7
Discovering services
Services discovery completed.
CBPeripheral:
<B4INativeObject: <CBPeripheral: 0x2816dd220, identifier = D2B289C7-6B84-990A-1D79-6553F0BBDB6D, name = DexcomW7, state = connected>>
<B4INativeObject: 2>
CBService:
<B4INativeObject: <CBService: 0x28328a180, isPrimary = YES, UUID = F8083532-849E-531C-C594-30F1F86A4EA5>>
<B4INativeObject: (null)>
<B4INativeObject: (null)>
Disconnect: <B4IExceptionWrapper: Error Domain=CBErrorDomain Code=7 "The specified device has disconnected from us." UserInfo={NSLocalizedDescription=The specified device has disconnected from us.}>
no dataavailable.
disconnect.

B4X:
Sub BleSrv_Connected(Services As List)
    BleSrv.ReadData("F8083532-849E-531C-C594-30F1F86A4EA5")
End Sub
 

Erel

Administrator
Staff member
Licensed User
Maybe you are supposed to write something to G5_MM_WRITE_CHARACTER_UUID immediately after the connection.
 

Moroz

Member
Licensed User
B4X:
Application_Start
Application_Active
Discovering services
Services discovery completed.
Error occurred on line: 106 (Main)
You must first call ReadData and wait for DataAvailable event.
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  MyDex                -[BleManager getChar::] + 172
  MyDex                -[BleManager writeData::::] + 268
  MyDex                -[BleManager WriteData:::] + 84
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  MyDex                +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
  MyDex                -[B4IShell runVoidMethod] + 232
 MyDex                -[B4IShell raiseEventImpl:method:args::] + 1792
 MyDex                -[B4IShellBI raiseEvent:event:params:] + 1372
 MyDex                +[B4IObjectWrapper raiseEvent:::] + 300
 MyDex                -[BlePeripheralDel peripheral:didDiscoverServices:] + 708
 CoreBluetooth        <redacted> + 932
 CoreBluetooth        <redacted> + 352
 CoreBluetooth        <redacted> + 204
 CoreBluetooth        <redacted> + 60
 libdispatch.dylib    <redacted> + 24
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 592
 libdispatch.dylib    <redacted> + 480
 libdispatch.dylib    <redacted> + 784
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1924
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 104
 UIKitCore            UIApplicationMain + 212
 MyDex                main + 124
 libdyld.dylib        <redacted> + 4
)
No need ReadData first
 

Erel

Administrator
Staff member
Licensed User
What I meant is - that it is possible that the device disconnects after a few seconds if you aren't writing something that it expects.
 

Moroz

Member
Licensed User
BleSrv.WriteData("F8083532-849E-531C-C594-30F1F86A4EA5","F8083534-849E-531C-C594-30F1F86A4EA5",Array As Byte(0x01,0x32,0x33,0x35,0x37,0x30,0x31,0x34,0x35,0x02))

it's a autorisation packet to this device.
 

Moroz

Member
Licensed User
In general, by analyzing the Native code from Spike, the device responds only after authorization.
Accordingly, the algorithm is as follows:
1. Find the device.
2. We take out what services it has.
3. After the main service we request characteristics.
4. After that we send an authorization package. (if you read at this stage, the device does not respond and expands the connection)

As far as I understand, you first have a request for characteristics, and after reading from the service?
Tell me how I can, with the help of Nativobject, process the request for characteristics, without further reading.

Sorry my bad english )))
 
Last edited:

Moroz

Member
Licensed User
No did it after connecting to the device.


Could you tell me why I can’t call a method on the CBPeripheral NativeObject

DiscoveryCharacteristics:WithService
???
Method not found - error take.

P.S.
I wanted to add, the same situation happens on Android devices with a library
 
Last edited:
Top