0
votes

I'm developing iOS application which works as BLE central with custom services and characteristics.

And the peripheral device is developed by a certain vendor.

The system needs pairing between central and peripheral to write characteristic value. And now I have a problem regarding the pairing.

If I delete paring information on central(iPhone) side by [Forget This Device] in [Bluetooth] of [Settings],
the paring sequence starts again when my application try to write characteristic value after connection and discover service and characteristic. (Paring dialogue shows on my application)

The sequence is like below,

 1. Complete connection
     [_centralMgr centralManager:didConnectPeripheral:]
 2. Discover service
 [_centralMgr peripheral:didDiscoverServices:]
 3. Discover characteristic
 [_centralMgr peripheral:didDiscoverCharacteristicsForService:error:]
 4. Try to write characteristic value
 [_centralMgr peripheral:writeValue:forCharacteristic:tyep:]
 5. At this timing, paring  dialog is shown and user tap [Paring] button
 6. Complete writing of characteristic value without error
 [_centralMgr peripheral:didWriteValueForCharacteristic:error:]

But if I delete paring information on peripheral device side (by reset the device), the paring sequence doesn't start when my application try to write characteristic value after connection and discover service and characteristic.

Paring dialogue never shows and the response for write request doesn't return.

The sequence is like below,

 1. Complete connectiton
 [_centralMgr centralManager:didConnectPeripheral:]
 2. Discover service
 [_centralMgr peripheral:didDiscoverServices:]
 3. Discover characteristic
 [_centralMgr peripheral:didDiscoverCharacteristicsForService:error:]
 4. Try to write characteristic  value
 [_centralMgr peripheral:writeValue:forCharacteristic:tyep:]
 5. At this timing, paring dialog is never shown
 6. Response of writing request(in STEP 4.) doesn't return

The vendor of peripheral device is saying that iPhone doesn't request paring even the peripheral device returns write error.

But my application(at least application layer in iOS) doesn't did receive the delegate API of writing error.

Is there anyone who have a same problem ? I'd appreciate it if you would provide some hint or information.

Add the code of writing characteristic value

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(nonnull CBService *)service error:(nullable NSError *)error
{
    NSArray* characteristics = service.characteristics;

    for (CBCharacteristic* characteristic in characteristics) {
        if (characteristic.properties & CBCharacteristicPropertyWrite) {
            if ([[characteristic.UUID UUIDString] isEqualToString:MY_CUSTOM_CHARACTERISTIC]) {
                NSData* data = MY_CUSTOM_DATA;
                [peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
                NSLog(@"writeValue:%@", data);
            }
        }
    }
}

In both case(after deleting pairing info. on central/peripheral side), it discovers completely the same characteristic and write same data.

But only in the latter case(deleted on peripheral side), pairing sequence doesn't start.

1
Can you post the related parts of codes (not just the functions you use)?Raptor
The behaviour seems understandable to me. You have deleted the bonding key data from the peripheral but not from iOS, so iOS thinks it still has valid bonding information and won't initiate the bonding request. However, you can lodge a bug/support request to Apple and see what they say. There is nothing explicit you can do through Core Bluetooth to clear or initiate the pairing/bonding processPaulw11
@Raptor I added the code of writing characteristic value. Thank you.M.Masa
@Paulw11 My team also developing android application and the engineer of peripheral device said android request paring again if the peripheral returns the write error after deleting pairing info. on peripheral side. And I posted the same question on iOS dev forum. I will ask in Technical Support Incident(TSI) if needed. Thank you.M.Masa

1 Answers

0
votes

In this case accessory(peripheral) should ask for pairing not phone. It should be handle on the firmware side. When it receive a write request for a Characteristic (only when encryption required) if its not already paired it should ask for pairing. Ask you vendor to handle it your side is all good.