BLE getCharacteristicByUUID / getValue(buf, 128) only returns 20 bytes

Hello all,

I am trying to use a Boron (as central device) to read a characteristic on another BLE device. This characteristic contains only a single array of 128 bytes. When I read the data from that characteristic:

BleCharacteristic   ble_char;
byte  char_data[128];

ble_peer.getCharacteristicByUUID(ble_char, BleUuid("4149524C-03B7-0014-0004-000000000001");
ble_char.getValue(char_data, 128);

Only the first 20 bytes are returned. Any ideas as to how I retrieve the remaining 108 bytes from this characteristic? I am able to read it just fine from smartphone applications such as nrfConnect and Lightblue without any problems.

Thanks.

  • Chris

Second one - can you please use BLE category? Thanks

@happicow , did you ever figure out how to get the full characteristic value?

I'm facing the same thing with a 32-byte string, only 20 bytes are retrieved:

BleCharacteristic externalId;
bool r1 = peer.getCharacteristicByUUID(externalId, BleUuid(BLE_EXTERNAL_ID_CHARACTERISTIC));

// Note r1 is for illustration, it does indeed return 1

String externalIdValue;
externalId.getValue(externalIdValue);
Log.info("externalId: %s", externalIdValue.c_str());

This should be 32 bytes.

I didn't look at the BLE docs, but coincidentally:

Could it be a decimal/hexa thingy?

Two things...

The device you are connecting to must support BLE v4.2 or higher to retrieve characteristics that are larger than 20 bytes.

Next you need to increase the MTU Particle will use to transmit characteristics. I am running Particle OS 5.4.1 and am using the following command to do that. If I recall, this command may have been different prior to v4.0.0.

    // Set our maximum MTU 
    hal_ble_gatt_server_set_desired_att_mtu(sizeof(characteristic) + 4, nullptr);

Thanks for your comment @gusgonnet .

I'm packaging up the following value on sending from the peripheral (iPhone):

95abad4aafb14261b11e0848bc94be72

And this is what the Central (Boron 404X) is showing for the characteristic its in:

95abad4aafb14261b11e8

I'm going to bet you... that that 0 in there is being treated as a null terminator! Let me go take a look and see.

Update: I would have lost the bet. Back to the drawing board.

1 Like

Thanks @happicow . In my scenario the device being connected to is an iPhone 12. The Particle is isn't transmitting characteristics, its reading what the iPhone is transmitting. The Particle is a Boron 404X running DeviceOS 5.7.

It is most peculiar, and definitely truncated at 20 characters. I'll continue to look at the MTU.

Just an update here - I really need to cut my losses and move on so I chose a different identifier to send in the characteristic. However I do want to circle back at some point and continuing troubleshooting because either a) everyone has this issue or b) someone has already solved it.

1 Like