Skip to content

Add setMTU function to BLEClient.cpp/.h #4999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions libraries/BLE/src/BLEClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <esp_bt_main.h>
#include <esp_gap_ble_api.h>
#include <esp_gattc_api.h>
#include <esp_gatt_common_api.h>// ESP32 BLE
#include "BLEClient.h"
#include "BLEUtils.h"
#include "BLEService.h"
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion libraries/BLE/src/BLEClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down