Activate BLE Bonding and security with Button and show special services

Rx-365
Posts: 10
Joined: Wed Jan 17, 2018 12:08 am

Re: Activate BLE Bonding and security with Button and show special services

Postby Rx-365 » Mon Jul 08, 2019 5:22 pm

Any updates on this issue? I believed that the Whitelisting was still broken, thus the path you ended up going down would not work.

I have tried several attempts to solve this problem and ended up with little to no success. At the moment I am trying to detect if a connection has a Long Term BLE Key stored on my device when a connection is opened. If the long term key exists I will let the device connect otherwise I will reject the connection. It isn't looking promising though.

Rx-365
Posts: 10
Joined: Wed Jan 17, 2018 12:08 am

Re: Activate BLE Bonding and security with Button and show special services

Postby Rx-365 » Wed Jul 10, 2019 4:02 pm

Alright, this may not be a solution for you, but it worked for my problem.

What I believe you should do is change the security level when the button is pressed and then change it back for ten seconds. By default you should set the security level to:

Code: Select all

esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND;
    esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
This will allow previously bonded connections to bypass the GAP layer and stop all new connections. Once the button is pressed run the code:

Code: Select all

esp_ble_auth_req_t auth_req = ESP_LE_AUTH_BOND;     //bonding with peer device after authentication
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
This will allow connections to create new bonds. Let me know if this works for you. Again, this solution does not handle GATT layer permissions. This simply controls the window in which new devices are able to access your BLE interface.

Alex_Bul
Posts: 1
Joined: Sun Jan 02, 2022 9:01 pm

Re: Activate BLE Bonding and security with Button and show special services

Postby Alex_Bul » Sun Jan 02, 2022 9:13 pm

I know it's being a long time since the question posted. "Why device is unvisable after disconnect?"

But today I solved similar problems and some good peoples help me. So I have to share this with followers.
The only thing we have to do after client (this means smartphone) connect to the server (this is our ESP BLE module, board or device) is to start advertisibg again.
Just like this:

class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
//Here restart advertising
pServer->getAdvertising()->start();
};

void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
//Or it can be done here after distonnection of the first client to prevent from probability of multi connection at the same time
pServer->getAdvertising()->start();//Here restart advertising
};
};

Who is online

Users browsing this forum: SvanteKaiser and 51 guests