Skip to content

Commit 828bf8e

Browse files
author
Eric Albers
committed
Add setMTU function to BLEClient.cpp/.h
1 parent 46d5afb commit 828bf8e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

libraries/BLE/src/BLEClient.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,39 @@ uint16_t BLEClient::getMTU() {
545545
return m_mtu;
546546
}
547547

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

libraries/BLE/src/BLEClient.h

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