I am dealing with BluetoothLow Energy problem. I find my peripheral BLE device with iPhone, connect to it, also find service and the characteristic which is in write mode. But when I try to send some data, nothing happens - device doesn't receive anything and also - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
is not called.
My writeValue method is here:
-(void) writeValue:(int)serviceUUID characteristicUUID:(int)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data {
CBUUID *UUIDService = [CBUUID UUIDWithString:[NSString stringWithFormat:@"%@",TRANSFER_SERVICE_UUID]];
CBUUID *UUIDCharacteristic = [CBUUID UUIDWithString:[NSString stringWithFormat:@"%@",TRANSFER_CHARACTERISTIC_UUID]];
NSLog(@"ALERT");
CBService *service = [self findServiceFromUUID:UUIDService p:p];
if (!service)
{
NSLog(@"Could not find service with UUID %@ on peripheral with UUID %@",
[self CBUUIDToString:UUIDService],
p.identifier.UUIDString);
return;
}
CBCharacteristic *characteristic = [self findCharacteristicFromUUID:UUIDCharacteristic service:service];
if (!characteristic)
{
NSLog(@"Could not find characteristic with UUID %@ on service with UUID %@ on peripheral with UUID %@",
[self CBUUIDToString: UUIDCharacteristic],
[self CBUUIDToString:UUIDService],
p.identifier.UUIDString);
return;
}
NSString *message = @"AB";
NSData *dataMsg= [message dataUsingEncoding:NSUTF8StringEncoding];
[p writeValue:dataMsg forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
}
What could be the problem?
peripheral:didWriteValueForCharacteristic:error:
called? What doesfindCharacteristicFromUUID:
? – Larmeperipheral:didWriteValueForCharacteristic:error:
is NOT called either.findCharacteristicFromUUID:
simply checks if UUID which I wrote is the same as one of the service's characteristics: ` -(CBCharacteristic ) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService)service { for(int i=0; i < service.characteristics.count; i++) { CBCharacteristic *c = [service.characteristics objectAtIndex:i]; if ([self compareCBUUID:c.UUID UUID2:UUID]) return c; } return nil; //Characteristic not found on this service } ` – JInncharacteristic
when you found it? – Larme