diff --git a/libraries/BLE/src/BLEClient.cpp b/libraries/BLE/src/BLEClient.cpp index 18e06f2a2d3..6f099c40335 100644 --- a/libraries/BLE/src/BLEClient.cpp +++ b/libraries/BLE/src/BLEClient.cpp @@ -10,6 +10,7 @@ #include #include #include +#include // ESP32 BLE #include "BLEClient.h" #include "BLEUtils.h" #include "BLEService.h" @@ -545,6 +546,39 @@ uint16_t BLEClient::getMTU() { return m_mtu; } + +/** + @brief Set the local and remote MTU size. + Should be called once after client connects if MTU size needs to be changed. + @return bool indicating if MTU was successfully set locally and on remote. +*/ +bool BLEClient::setMTU(uint16_t mtu) +{ + esp_err_t err = esp_ble_gatt_set_local_mtu(mtu); //First must set local MTU value. + if (err == ESP_OK) + { + err = esp_ble_gattc_send_mtu_req(m_gattc_if,m_conn_id); //Once local is set successfully set remote size + if (err!=ESP_OK) + { + log_e("Error setting send MTU request MTU: %d err=%d", mtu,err); + return false; + } + } + else + { + log_e("can't set local mtu value: %d", mtu); + return false; + } + log_v("<< setLocalMTU"); + + m_mtu = mtu; //successfully changed + + return true; +} + + + + /** * @brief Return a string representation of this client. * @return A string representation of this client. diff --git a/libraries/BLE/src/BLEClient.h b/libraries/BLE/src/BLEClient.h index faf2f0c345b..2550274c9f0 100644 --- a/libraries/BLE/src/BLEClient.h +++ b/libraries/BLE/src/BLEClient.h @@ -57,7 +57,8 @@ class BLEClient { uint16_t getConnId(); esp_gatt_if_t getGattcIf(); uint16_t getMTU(); - + bool setMTU(uint16_t mtu); + uint16_t m_appId; private: friend class BLEDevice;