Reputation: 965
Context: - iOS 7.1.2 on iPhone 5c - A glucose measuring "peripheral" (BT LE) - Device and peripheral have been paired (introducing a code) - Peripheral has >= 1 records on/in it. - The behavior described below was reproduced several times. With the peripheral only having one record, and as well having made two new ones. The results (characteristic.value's) read are always the same.
I'm trying to read (receive) records from the peripheral using an iOS device the following way:
peripheral:didDiscoverServices:error:
discover characteristics, which are Glucose Measurement (0x2A18), Glucose Measurement Context (0x2A34), Glucose Feature (0x2A51) and Record Access Control Point (0x2A52)peripheral:didDiscoverCharacteristicsForService:error:
iterate over all characteristics and read values for those characteristics (via [_peripheral readValueForCharacteristic:characteristic]
)[_peripheral setNotifyValue:YES forCharacteristic:characteristic]
(for all but the "Glucose Feature" characteristic). This is triggered via a button click, when "everything has been loaded".Request number of records available (triggered by user) via "Record Access Control Point" like:
char buffer[3];
// Op Code: 0x04 report number of stored records
buffer[0] = 0x04;
// Operator: 0x01 All records
buffer[1] = 0x01;
// Operand: 0x00 n/a
buffer[2] = 0x00;
NSData *data = [NSData dataWithBytes:buffer length:3];
[_peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
peripheral:didUpdateValueForCharacteristic:error:
delegate method and the updated value is 06000405
. I don't fully understand the related specification (see link below), so I'm not able to interpret the response my self but either 5 or 6 in the LSO (Least Significant Octet) would mean a "success" (or at least not an error).Trigger the request of all stored records (triggered by user) like:
char buffer[3];
// Op Code: 0x01 report stored records
buffer[0] = 0x01;
// Operator: 0x01 All records, 0x06 last one
buffer[1] = 0x01; // Tried 0x06 as well with the same result
// Operand: 0x00 n/a
buffer[2] = 0x00;
NSData *data = [NSData dataWithBytes:buffer length:3];
[_peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
peripheral:didUpdateValueForCharacteristic:error:
with an updated value of 06000105
. Changing the second octet from 0x01
to 0x06
gave the same response (value). Which as well I'm not able to understand/interpret.Note: On Android it seems that one must also set the Client Characteristic Configuration descriptor to notify and/or indicate, but trying either of that results in an exception and a message that notifications should be set on the characteristic itself using setNotifyValue:forCharacteristic:
on the peripheral.
My main problem is, that there are no callbacks to peripheral:didUpdateValueForCharacteristic:error:
on Glucose Measurement characteristic including the records. I event tried calling [_peripheral setNotifyValue:YES forCharacteristic:characteristic]
again on that characteristic, after requesting the records.
Does anyone see where my error(s) lie? Does anyone achieved (on iOS) what I'm trying to achieve?
Another thing is the BT glucose service specification. I would greatly appreciate, if someone could enlighten me as on how to interpret the responses (means the updated values of the Record Access Control Point characteristic) I get. As I'm not even sure in which order the bytes in the characteristic.value
come (e.g. when they are read via getBytes:length:
method of NSData
).
I think I'm following the process described in the Glucose Profile specification so I'm really at a loss here.
Thank you very much in advance!
Best regards, Gabriel
Upvotes: 1
Views: 1585
Reputation: 197
Having encountered the same issue, I was unable to work out how to interpret the 06000105 value, however I think that is an error response code of sorts.
What fixed the issue for me was to exclude the Operand if it was null, and only use the Op Code and Operator:
char buffer[2];
// Op Code: 0x01 report stored records
buffer[0] = 0x01;
// Operator: 0x01 All records, 0x06 last one
buffer[1] = 0x01;
NSData *data = [NSData dataWithBytes:buffer length:2];
...
Then all the records came flowing in as expected in didUpdateValueForCharacteristic
Upvotes: 2