mbaytas
mbaytas

Reputation: 3024

Sending 20-byte characteristic values with CurieBLE

The documentation for Arduino/Genuino 101's CurieBLE library states the following, in the section "Service Design Patterns":

A characteristic value can be up to 20 bytes long. This is a key constraint in designing services. [...] You could also combine readings into a single characteristic, when a given sensor or actuator has multiple values associated with it.

[e.g. Accelerometer X, Y, Z => 200,133,150]

This is more efficient, but you need to be careful not to exceed the 20-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as a ASCII-encoded string.

However, the typed Characteristic constructors available in the API are limited to the following:

  • BLEBoolCharacteristic
  • BLECharCharacteristic
  • BLEUnsignedCharCharacteristic
  • BLEShortCharacteristic
  • BLEUnsignedShortCharacteristic
  • BLEIntCharacteristic
  • BLEUnsignedIntCharacteristic
  • BLELongCharacteristic
  • BLEUnsignedLongCharacteristic
  • BLEFloatCharacteristic
  • BLEDoubleCharacteristic

None of these types of Characteristics appear to be able to hold a 20-byte string. (I have tried the BLECharCharacteristic, and it appears to pertain to a single char, not a char array.)

Using CurieBLE, how does one go about using a string as a characteristic value, as described in the documentation as an efficient practice?

Upvotes: 2

Views: 5049

Answers (1)

Vladimir T
Vladimir T

Reputation: 866

Yours issue described here in official arduino 101 example. Few strings of code how to set an array:

BLECharacteristic heartRateChar("2A37",  // standard 16-bit characteristic UUID
    BLERead | BLENotify, 2);
...
const unsigned char heartRateCharArray[2] = { 0, (char)heartRate };
heartRateChar.setValue(heartRateCharArray, 2);

As you can see characteristic's value set using "setValue" function with desired array as an argument. You can pass a String as char* pointing to an array.

Upvotes: 1

Related Questions