ArduinoBLE : readValue how do I indicate the byte has been read?

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?

Read the values into a buffer with .readValue(buffer, length).

Syntax

bleCharacteristic.readValue(buffer, length)
bleCharacteristic.readValue(value)

Parameters

  • buffer: byte array to read value into length: size of buffer argument in bytes
  • value: variable to read value into (by reference)

Returns

  • Number of bytes read

Thanks for the offering of help. I don't think I was clear enough.

in the iOS app I've sent a string like, "test"

However, when I use readValue() on the arduino side to read the bytes, I only see 1 byte and it is the first byte only.

I expected this to work more similarly to reading from Serial. Once you read the byte, it is pulled off the stream and you read the next byte.

However, in this case, it seems I can only read the first byte.

So, for example, if I loop & keep calling readValue() it just keeps getting that first byte.
Why is that? How do I read the subsequent bytes?
Or, another way to ask might be, "How do I pop the bytes off the thing when I read them?...so I can get to the next byte?"
Thanks,

I found BLEStringCharacteristic after scanning over more pages.
I changed my BLEByteCharacteristic & now I can read multiple bytes (a String).
This stuff is very poorly documented & BLE is a monster to deal with.
Using BLEStringCharacteristic is the solution to this problem. Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.