Bonjour,
j'essaye de connecter mon arduino avec mon application iphone par bluetooth. Le principe est:
1. l'iphone envoie le chiffre '1' pour lancer la réception de donnée
2. l'arduino envoi ses données dans un buffer
3. l'ios doit afficher les données reçues
1 et 2 fonctionne mais je n'arrive pas à faire la 3eme etape, récupérer les données reçues ..
J'ai comme erreur: Error reading data: Error Domain=CBErrorDomain Code=8 "The specified UUID is not allowed for this operation."
voila une partie de mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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); } }
Partager