iOS 从 "Accu-Chek Aviva Connect" 血糖仪收集数据的应用程序。 (低功耗蓝牙)
iOS app that collects data from "Accu-Chek Aviva Connect" BG meter. (Bluetooth Low Energy)
我正在尝试创建一个 iOS 应用程序,它将从 Accu-Chek Aviva Connect.
收集数据
为了与 BG 仪表配对,我向记录访问控制点特征发送写入请求:
- (void)peripheral:(CBPeripheral *)aPeripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
if ([service.UUID isEqual:[CBUUID UUIDWithString:@"1808"]]) {
for (CBCharacteristic *aChar in service.characteristics) {
// Read Glucose Measurement...
// Read Glucose Measurement Context...
// Read Glucose Feature...
// Read Date Time...
// Read Record Access Control Point
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:@"2A52"]]) {
[aPeripheral readValueForCharacteristic:aChar];
[aPeripheral setNotifyValue:YES forCharacteristic:aChar];
uint8_t bytes[] = {0x04, 0x01, 0x00};
NSData *data = [NSData dataWithBytes:(void*)&bytes length:sizeof(bytes)];
[aPeripheral writeValue:data forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];
}
}
}
}
在 iPhone 上,我看到一个 UIAlert,其中包含用于输入安全代码的字段。我可以将 iPhone 与 Accu-Chek Aviva Connect 配对。但是下次我向 Record Access Control Poin Characteristic 发送一些写请求时(在设备断开连接后)我得到 "Error: Authentication is insufficient" 并且没有 UIAlert在 iPhone.
我觉得我做的每件事都是错的。
我想从蓝牙设备的日志中读取记录。 AFAIU 我将字节写入读取记录访问控制点 ([aPeripheral writeValue:data forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];
) 并在 peripheral:didWriteValueForCharacteristic:error:
中得到答案。但我做不到,因为 "Error: Authentication is insufficient" 挡住了我的路!
您需要通过身份验证才能向血糖仪发出写入请求。身份验证不足意味着您试图在未经过身份验证的情况下发出请求。您不能只连接然后写入医学相关特征。
检查您是否真的发出了身份验证请求(这也需要输入 PIN)。如果是,请检查 PIN 码是被接受还是被拒绝。
使用 Accu-Chek Aviva Connect 的方法是在第一次配对时前往 Settings
→ Wireless
→ Pairing
→ Pair Device
。
然后您会看到一个带有数字代码的屏幕和一条消息:"Enter code on device".
在 iPhone 上,您发现了 Accu-Chek 设备并将一个值写入读取记录访问控制点特征。例如请求一条记录数:
- (void)peripheral:(CBPeripheral *)aPeripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
if ([service.UUID isEqual:[CBUUID UUIDWithString:@"1808"]]) {
for (CBCharacteristic *aChar in service.characteristics) {
// Read Record Access Control Point
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:@"2A52"]]) {
[aPeripheral readValueForCharacteristic:aChar];
[aPeripheral setNotifyValue:YES forCharacteristic:aChar];
self.readAccessControlPointCharacteristic = aChar;
NSMutableData *mutableData = [NSMutableData data];
uint8_t opCode = 0x04; // Report number of stored records
uint8_t operator = 0x01; // All records
[mutableData appendData:[NSData dataWithBytes:(void*)&opCode length:sizeof(opCode)]];
[mutableData appendData:[NSData dataWithBytes:(void*)&operator length:sizeof(operator)]];
[aPeripheral writeValue:mutableData forCharacteristic:self.readAccessControlPointCharacteristic type:CBCharacteristicWriteWithResponse];
}
}
}
这会导致 iPhone 上出现 UIAlertView,它要求您输入显示在 Accu-Chek 屏幕上的代码。当您这样做时,您的 iPhone 将与 Accu-Chek Aviva Connect 成功配对。
现在。当你想从蓝牙设备读取所有记录时 - 你必须去 My Data
→ Data Transfer
→ Wireless
→ 如果你的 Accu-Chek 设备有很多配对,select 你的 iPhone 名字。 注意: iPhone 必须正在扫描 BT 设备并自动连接到发现的设备。
蓝牙连接将建立,您可以从 iPhone 向蓝牙设备发送任何请求,无需 "Error: Authentication is insufficient"!
我正在尝试创建一个 iOS 应用程序,它将从 Accu-Chek Aviva Connect.
收集数据为了与 BG 仪表配对,我向记录访问控制点特征发送写入请求:
- (void)peripheral:(CBPeripheral *)aPeripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
if ([service.UUID isEqual:[CBUUID UUIDWithString:@"1808"]]) {
for (CBCharacteristic *aChar in service.characteristics) {
// Read Glucose Measurement...
// Read Glucose Measurement Context...
// Read Glucose Feature...
// Read Date Time...
// Read Record Access Control Point
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:@"2A52"]]) {
[aPeripheral readValueForCharacteristic:aChar];
[aPeripheral setNotifyValue:YES forCharacteristic:aChar];
uint8_t bytes[] = {0x04, 0x01, 0x00};
NSData *data = [NSData dataWithBytes:(void*)&bytes length:sizeof(bytes)];
[aPeripheral writeValue:data forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];
}
}
}
}
在 iPhone 上,我看到一个 UIAlert,其中包含用于输入安全代码的字段。我可以将 iPhone 与 Accu-Chek Aviva Connect 配对。但是下次我向 Record Access Control Poin Characteristic 发送一些写请求时(在设备断开连接后)我得到 "Error: Authentication is insufficient" 并且没有 UIAlert在 iPhone.
我觉得我做的每件事都是错的。
我想从蓝牙设备的日志中读取记录。 AFAIU 我将字节写入读取记录访问控制点 ([aPeripheral writeValue:data forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];
) 并在 peripheral:didWriteValueForCharacteristic:error:
中得到答案。但我做不到,因为 "Error: Authentication is insufficient" 挡住了我的路!
您需要通过身份验证才能向血糖仪发出写入请求。身份验证不足意味着您试图在未经过身份验证的情况下发出请求。您不能只连接然后写入医学相关特征。
检查您是否真的发出了身份验证请求(这也需要输入 PIN)。如果是,请检查 PIN 码是被接受还是被拒绝。
使用 Accu-Chek Aviva Connect 的方法是在第一次配对时前往 Settings
→ Wireless
→ Pairing
→ Pair Device
。
然后您会看到一个带有数字代码的屏幕和一条消息:"Enter code on device".
在 iPhone 上,您发现了 Accu-Chek 设备并将一个值写入读取记录访问控制点特征。例如请求一条记录数:
- (void)peripheral:(CBPeripheral *)aPeripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
if ([service.UUID isEqual:[CBUUID UUIDWithString:@"1808"]]) {
for (CBCharacteristic *aChar in service.characteristics) {
// Read Record Access Control Point
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:@"2A52"]]) {
[aPeripheral readValueForCharacteristic:aChar];
[aPeripheral setNotifyValue:YES forCharacteristic:aChar];
self.readAccessControlPointCharacteristic = aChar;
NSMutableData *mutableData = [NSMutableData data];
uint8_t opCode = 0x04; // Report number of stored records
uint8_t operator = 0x01; // All records
[mutableData appendData:[NSData dataWithBytes:(void*)&opCode length:sizeof(opCode)]];
[mutableData appendData:[NSData dataWithBytes:(void*)&operator length:sizeof(operator)]];
[aPeripheral writeValue:mutableData forCharacteristic:self.readAccessControlPointCharacteristic type:CBCharacteristicWriteWithResponse];
}
}
}
这会导致 iPhone 上出现 UIAlertView,它要求您输入显示在 Accu-Chek 屏幕上的代码。当您这样做时,您的 iPhone 将与 Accu-Chek Aviva Connect 成功配对。
现在。当你想从蓝牙设备读取所有记录时 - 你必须去 My Data
→ Data Transfer
→ Wireless
→ 如果你的 Accu-Chek 设备有很多配对,select 你的 iPhone 名字。 注意: iPhone 必须正在扫描 BT 设备并自动连接到发现的设备。
蓝牙连接将建立,您可以从 iPhone 向蓝牙设备发送任何请求,无需 "Error: Authentication is insufficient"!