How to read information from core bluetooth device

徘徊边缘 提交于 2019-11-30 12:26:29

Take a nice good read through the framework. if you have come this far you shouldn't have any problem finding 'discoverCharacteristics' and the peripheral delegate callback 'didDiscoverCharacteristic'. You need to know the UUID of the services and characteristics you want to discover and apply it to those methods.

Then you can read with 'readValueForCharacteristic' and the delegate callback 'didUpdateValueForCharacteristic'.

This is sent from my phone, so I will maybe edit a bit when I get to a computer. Hope it helps

New question:

[connectedPeripheral readValueForCharacteristic:wantedCharacteristic] 

and at peripheral delegate

- (void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{

NSLog(@"Characteristic value : %@ with ID %@", characteristic.value, characteristic.UUID);
[delegate characteristicValueRead:characteristic.value];
}

works for me

You can get value of a characteristic

 NSString *value = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];

NSLog(@"Value %@",value);

Just use https://github.com/LGBluetooth/LGBluetooth

    [LGUtils readDataFromCharactUUID:@"f045"
                          seriveUUID:@"5ec0"
                          peripheral:peripheral
                          completion:^(NSData *data, NSError *error) {
                              NSLog(@"Data : %s Error : %@", (char *)[data bytes], error);
                          }];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!