Hi all! I'm trying send a long data (~2150 bytes) through the readValueForCharacteristic like that:
self.peripheralInfoCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:READ_INFO_PERIPHERAL_UUID] properties:CBCharacteristicPropertyRead value:nil permissions:CBAttributePermissionsReadable];
Central requesting the characteristic value:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
if (error) {
NSLog(@"Error discovering characteristics: %@", [error localizedDescription]);
return;
}
for (CBCharacteristic *characteristic in service.characteristics) {
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:READ_INFO_PERIPHERAL_UUID]]){
[self.discoveredPeripheral readValueForCharacteristic:characteristic];
} else if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:WRITE_CENTRAL_INFO_UUID]]){
[self.discoveredPeripheral writeValue:[self.myUserInfo transformJsonData] forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse];
}
}
}
When central is requesting exactly 628 bytes, the process is working like a charm! But when i's requesting 2150 bytes, the next steps occurs:
On peripheral: (this method is called 4 times, where offset = {0, 157, 314, 471})
- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveReadRequest:(CBATTRequest *)request{
if ([request.characteristic.UUID.UUIDString isEqualToString:READ_INFO_PERIPHERAL_UUID]){
if (request.offset > peripheralInfoCharacteristicData.length) {
[peripheral respondToRequest:request withResult:CBATTErrorInvalidOffset];
return;
}
request.value = [peripheralInfoCharacteristicData subdataWithRange:NSMakeRange(request.offset, peripheralInfoCharacteristicData.length - request.offset)];
[self.peripheralManager respondToRequest:request withResult:CBATTErrorSuccess];
}
}
After that on Central:
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
if ([characteristic.UUID.UUIDString isEqualToString:READ_INFO_PERIPHERAL_UUID]){
// characteristic.value is equal 628. It is wrong! Should be 2150
// So I can't deserialize the NSData
}
}
So what is wrong? It is not possible pass >628 bytes on readValueCharacteristic?
When I using writeValueCharacteristic the didReceiveWriteRequests isn't called, just when I pass 628- bytes.
This is my first message here, so I hope that's not break any rule.
Thanks in advance.
--
Thiago Rios