How to use setMTU in BLE library.

haddow777
Posts: 14
Joined: Tue Jul 13, 2021 3:25 pm

How to use setMTU in BLE library.

Postby haddow777 » 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:

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)
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.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: How to use setMTU in BLE library.

Postby chegewara » Thu Aug 05, 2021 9:43 am

You are using example from arduino-esp32 and library that is not a part of arduino-esp32.
https://github.com/espressif/arduino-es ... e4dcb0e639

haddow777
Posts: 14
Joined: Tue Jul 13, 2021 3:25 pm

Re: How to use setMTU in BLE library.

Postby haddow777 » Thu Aug 05, 2021 12:46 pm

Okay, so now I'm thoroughly confused. I setup PlatformIO like all the docs said to. It installed the proper platform and had me select the Arduino framework, but that framework is not the arduino-esp32 library, instead it's a mishmash of various libraries? Why?

I've been digging into it and for some reason, I can't seem to figure out how to use the Arduino-esp32 code in PlatformIO. There's instructions on how to install it in ArduinoIDE, but not PlatformIO. It doesn't make much sense, as when you dig into the files some, I can find references to PlatformIO.

I'm most likely missing something. If you or anyone else knows either how to install it in PlatformIO or if it's even possible, I could really use the help. The code I have been using is fairly close to what I found at espressif's repository, but further out of date. I don't really want to keep muddling in the code if it's an outdated library that's messing me up.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: How to use setMTU in BLE library.

Postby chegewara » Thu Aug 05, 2021 1:48 pm

Ok, in that case you are just using arduino framework which is older and does not include that PR.
What you need is arduino-esp32 v2.0.0-alpha or newer. Before you ask how to, please see this issue:
https://github.com/espressif/arduino-es ... -886165879

haddow777
Posts: 14
Joined: Tue Jul 13, 2021 3:25 pm

Re: How to use setMTU in BLE library.

Postby haddow777 » Fri Aug 06, 2021 9:32 pm

Thank you thank you thank you. I had managed in my own bludering trek through google to find the platform_packages line, but it failed to compile before. Now that you've shown me a site that lists the new temporary platform link to use, it's finally compiling in general and more specifically, also with the BLEClient::setMTU method from the example. Yay.

Who is online

Users browsing this forum: No registered users and 87 guests