I'm connecting to my Arduino Nano 33 BLE with no problems.
I'm able to send data from my iOS app.
I've set up a characteristic which basically takes one byte at a time.
I'm using the ArudinoBLE library to and calling readValue(), but I don't understand how to indicate that I have read the byte? How can the program know when it has read all of the bytes in the stream?
Here's a little code snippet to see what I'm doing in the loop but this grabs the bytes numerous times.
if (remoteSend.value()){
Serial.println("got data");
byteCount = remoteSend.readValue(outChar);
while (byteCount > 0 && counter <= 5){
if (outChar != NULL){
Serial.println(outChar,DEC);
byteCount = 0;
}
byteCount = remoteSend.readValue(outChar);
counter++;
}
}
The remoteSend
is the main BLE service I've set up.
I call the ArduinoBLE function value()
to insure there is something to read.
I then attempt to read the bytes with readValue() which returns the number of bytes read.
I thought when I call readValue() that eventually it would return 0 because there were no more bytes to read (the sending iOS app sends 10 bytes, for example).
However, this code executes many more times than 10-bytes worth.
How do I insure I'm only reading each byte one time? Is there another ArduinoBLE method I should be calling?