1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
NSString *UUIDString = CFBridgingRelease(CFUUIDCreateString(NULL, CFBridgingRetain(service.UUID)));
[self logMessage:[NSString stringWithFormat:@"%@: %@", UUIDString, service.debugDescription]];
for (CBCharacteristic *characteristic in service.characteristics) {
NSData * data ;
// j'envoie 1 au périphérique
data=[@"1" dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Characteristic %@",characteristic.UUID);
NSLog(@"Found Service, Characteristic, writing value");
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse];
// je lis le buffer reçu
[peripheral readValueForCharacteristic:characteristic];
}
}
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
if (!error) {
NSData *recData = characteristic.value;
UInt16 buffer = 0;
[recData getBytes:&buffer range:NSMakeRange(0, 6)];
// NSLog(@"data : : %hu", buffer);
// UInt16 val1 = [self swap:buffer];
// NSLog(@"data : : %@", recData);
} else {
NSLog(@"Error reading data: %@", error);
}
} |