I am trying to figure out how to parse the value from a Bluetooth device with a characteristic which has more than 20 bytes in its value.
I have the code below which basically fires each time the characteristic value is updated. However, because the total amount of values is long, it seems that the didUpdateValueFor function seems to put out 4 or 5 notifications before I get the total amount of data. At the moment, I am looping through the value and appending to an array which I will use to graph some data. Is there a way to get all of the data into one array without having to do this loop each time? At the moment the data I am getting is as follows:
[89, 0, 44, 0, 84, 0, 112, 0, 125, 0, 125, 0, 134, 0, 144, 0, 153, 0, 162, 0]
[89, 1, 163, 0, 163, 0, 162, 0, 167, 0, 169, 0, 172, 0, 176, 0, 176, 0, 177, 0]
[89, 2, 182, 0, 181, 0, 181, 0, 182, 0, 181, 0, 169, 0, 164, 0, 157, 0, 139, 0]
[89, 3, 135, 0, 119, 0, 117, 0, 101, 0, 101, 0, 84, 0, 85, 0, 70, 0, 70, 0]
[84, 4, 55, 0, 46, 0, 26, 0, 21, 0]
The first value in each of the arrays is not important. However, the second value is a MS value and should be zero. However, each time the loop runs it seems to increment by one each time. Because I need to multiply this number by 256 (should the value of the LS value exceed 256), I am going to run into trouble if I simply ignore it (which is what my code does now as published below)
if characteristic.uuid == IDENTIFIER {
let v = characteristic.value;
print("this is what we have: \(value)")
//let numDataPoints = v![0] & 0x0f
let numDataPoints = v![0]
print("Number of data points:\(numDataPoints)")
for i in 1...v!.count-2 {
intIndex = Int(i)
let datapointnew = Int(v![intIndex!])
if datapointnew > 5 {
datapointArray.append(datapointnew)
} else {
datapointArray.append(0)
}
}
intIndex = 0
}
The second value in each of the array should be 0 with this set of data. Thanks in advance for any help you can offer.
vis an example of one of the 5 arrays mentioned in your question?