Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7a4e706

Browse filesBrowse files
authored
Add setMTU function to BLEClient.cpp/.h (espressif#4999)
The current implementation has a getMTU function which returns the mtu sent in a message. This function allows you to set the MTU value on the connected device, it first sets the MTU locally by calling esp_ble_gatt_set_local_mtu. It then calls esp_ble_gattc_send_mtu_req to have the connected device also change its MTU size.
1 parent f3dca15 commit 7a4e706
Copy full SHA for 7a4e706

File tree

Expand file treeCollapse file tree

2 files changed

+36
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+36
-1
lines changed

‎libraries/BLE/src/BLEClient.cpp

Copy file name to clipboardExpand all lines: libraries/BLE/src/BLEClient.cpp
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <esp_bt_main.h>
1111
#include <esp_gap_ble_api.h>
1212
#include <esp_gattc_api.h>
13+
#include <esp_gatt_common_api.h>// ESP32 BLE
1314
#include "BLEClient.h"
1415
#include "BLEUtils.h"
1516
#include "BLEService.h"
@@ -545,6 +546,39 @@ uint16_t BLEClient::getMTU() {
545546
return m_mtu;
546547
}
547548

549+
550+
/**
551+
@brief Set the local and remote MTU size.
552+
Should be called once after client connects if MTU size needs to be changed.
553+
@return bool indicating if MTU was successfully set locally and on remote.
554+
*/
555+
bool BLEClient::setMTU(uint16_t mtu)
556+
{
557+
esp_err_t err = esp_ble_gatt_set_local_mtu(mtu); //First must set local MTU value.
558+
if (err == ESP_OK)
559+
{
560+
err = esp_ble_gattc_send_mtu_req(m_gattc_if,m_conn_id); //Once local is set successfully set remote size
561+
if (err!=ESP_OK)
562+
{
563+
log_e("Error setting send MTU request MTU: %d err=%d", mtu,err);
564+
return false;
565+
}
566+
}
567+
else
568+
{
569+
log_e("can't set local mtu value: %d", mtu);
570+
return false;
571+
}
572+
log_v("<< setLocalMTU");
573+
574+
m_mtu = mtu; //successfully changed
575+
576+
return true;
577+
}
578+
579+
580+
581+
548582
/**
549583
* @brief Return a string representation of this client.
550584
* @return A string representation of this client.

‎libraries/BLE/src/BLEClient.h

Copy file name to clipboardExpand all lines: libraries/BLE/src/BLEClient.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class BLEClient {
5757
uint16_t getConnId();
5858
esp_gatt_if_t getGattcIf();
5959
uint16_t getMTU();
60-
60+
bool setMTU(uint16_t mtu);
61+
6162
uint16_t m_appId;
6263
private:
6364
friend class BLEDevice;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.