Hi, I’m working on a project that needs to send back-to-back characteristic writes to send a large payload of data (over 1MB) over BTLE. I’m using the Artemis chip, which supports BLE 5.0, including an MTU length up to 512 and an iOS device on the other side that also supports 512 length MTUs.
Along the way I’ve run in to a few troubles.
- I can use wireshark to sniff the BLE traffic to see what the MTU length was, but there was no way to see what it was from the code, and if I wrote beyond the length of the negotiated MTU then the left-overs were truncated… See here in wireshark:
What I thought would happen is the underlying BLE stack would use multiple packets to send my entire value… but unfortunately it just truncates and gives no error or warning and on the receiving end I get 242 bytes of my transmission only. Is there a solution to this anyone knows of?
I implemented my own that works well in BLEDevice.cpp by making these two additions:
//in BLEDevice.cpp
int BLEDevice::getMtuLength() const
{
return ATT.mtu(ATT.connectionHandle(_addressType, _address));
}
//in BLEDevice.h
int getMtuLength() const;
- Why does ArduinoBLE let you create a characteristic of 512 length if there’s no way to ever use that much length (if it is going to be truncated)? And I’ve tried changing all of the MTU lengths in att.c to 512 and no matter what the negotiated size will be 242 (even when the central size which is running on iOS offers 517 as can be seen in the screenshot above):
//512 is the max you can set this to and I don't know what the difference is between the last two params (valueLength and valueSize)...
BLECharacteristic bigDataChar("f5b64b90-14ed-11ec-82a1-0242ac130000", BLENotify, 512, 512);
Does anyone know what the best way would be to send back-to-back writes to this char and get maximum throughput with ArduinoBLE library?
Here’s what I’ve tried… When the characteristic is subscribed to the event handler for that does this:
void bigDataCharSubscribed(BLEDevice central, BLECharacteristic characteristic) {
int mtuLength = central.getMtuLength();//My new function I wrote above...
SerialPrint(F("bigDataCharSubscribed event, subscribed and MTU is: "));
Serial.println(mtuLength);
for(int i=0;i<100;i++){
char tempData[mtuLength];
char buf[8];
memset( tempData, 'a', sizeof(char)*mtuLength );
*(tempData + mtuLength - 8) = '\0';
itoa(i, buf, 10);
strcat(tempData,buf);
Serial.println(i);
characteristic.writeValue(tempData, strlen(tempData), true);
}
}
Any other tips for getting the most throughput out of Arduino BLE running on the Artemis?