h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
700 stars 145 forks source link

BLEClient, Setting CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH does not work #610

Closed nichtgedacht closed 10 months ago

nichtgedacht commented 10 months ago

Setting CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH=100 does not work

Neither Setting in platformio.ini as:

build_flags = -D CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH=100

nor uncommenting in nimconfig.h as:

define CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH 100

Notification data are still coming in chunks of 20 bytes.

h2zero commented 10 months ago

That macro only sets the size of the characteristic data buffer, not the data transmitted. The max size of a notification is determined by the MTU of the connection, so you would need to have a larger MTU on both devices.

nichtgedacht commented 10 months ago

MTU is reported as 256

NimBLEClient* pClient = NimBLEDevice::createClient(); ... Serial.printf("Got MTU: %d\n", pClient->getMTU());

Docu says: Set the default allocation size (bytes) for each attribute. If not specified when the constructor is called. This is also the size used when a remote characteristic or descriptor is constructed before a value is read/notifed. Increasing this will reduce reallocations but increase memory footprint. Default value is 20. Range: 1 : 512 (BLE_ATT_ATTR_MAX_LEN)

Why the length of data received from notifyCallback() is limited to 20 bytes?

h2zero commented 10 months ago

I cannot reproduce this. The max size of a notification is always MTU-3 as per the BLE specifications. The initial size of the characteristic data buffer is all that macro defines as it says in the documentation you've pasted.

There is ether only 20 bytes in your data or there is an MTU issue.

nichtgedacht commented 10 months ago

Thank you. I'll ask the manufacturer of the device whether they send data in this small portions.