How to use setMTU in BLE library.
Posted: Thu Aug 05, 2021 8:27 am
Hello. I'm fairly knew to arduino esp32 and am trying to learn BLE specifically at the moment. The problem I have is I am using the example code from Github, but it doesn't seem to line up with my code on PlatformIO.
Specifically, in the BLE_client example starting at line 45 we have a function connectToServer() which starts with:
You'll notice that last line is used to send a client request to max out the MTU. Now, I've checked BLEClient.cpp on GitHub. That method starts at line 555 of that file, so it does exist.
The problem I have though, is it doesn't exist in my library. I tried to run that example and I get an error saying the method doesn't exist. I can see the example being out of date, but the code would have to be out of date too. I've checked the library manager of PlatformIO and it says that the library is up to date.
I've does searches online, and this is where things get more confusing. I see lots of discussion with regards to setMTU, but they all talk about BLEDevice::setMTU(517). The also say you should use it right after BLEDevice::init. This sounds good and all, but then further googling says the client must send in a request to have the MTU adjusted, so both sides know they are using the same MTU value.
Does the BLEDevice::setMTU(value) method hold onto that value for clients and automatically make the request once the client connects to the server? If not, how come I don't have the BLEClient setMTU(num) method in my library.
Any help would be greatly appreciated. I've tried searching and even reading the code, but it's been a long time for me since I've used C++, so it's hard to say if I'm just missing something that would normally be obvious to you all. Thanks.
Specifically, in the BLE_client example starting at line 45 we have a function connectToServer() which starts with:
Code: Select all
bool connectToServer() {
Serial.print("Forming a connection to ");
Serial.println(myDevice->getAddress().toString().c_str());
BLEClient* pClient = BLEDevice::createClient();
Serial.println(" - Created client");
pClient->setClientCallbacks(new MyClientCallback());
// Connect to the remove BLE Server.
pClient->connect(myDevice); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
Serial.println(" - Connected to server");
pClient->setMTU(517); //set client to request maximum MTU from server (default is 23 otherwise)
The problem I have though, is it doesn't exist in my library. I tried to run that example and I get an error saying the method doesn't exist. I can see the example being out of date, but the code would have to be out of date too. I've checked the library manager of PlatformIO and it says that the library is up to date.
I've does searches online, and this is where things get more confusing. I see lots of discussion with regards to setMTU, but they all talk about BLEDevice::setMTU(517). The also say you should use it right after BLEDevice::init. This sounds good and all, but then further googling says the client must send in a request to have the MTU adjusted, so both sides know they are using the same MTU value.
Does the BLEDevice::setMTU(value) method hold onto that value for clients and automatically make the request once the client connects to the server? If not, how come I don't have the BLEClient setMTU(num) method in my library.
Any help would be greatly appreciated. I've tried searching and even reading the code, but it's been a long time for me since I've used C++, so it's hard to say if I'm just missing something that would normally be obvious to you all. Thanks.