Page 2 of 2

Re: BLE Security Passcode

Posted: Tue Dec 31, 2019 6:33 pm
by chegewara
Arduino passcode doesn’t work.
Need to use IDF examples.
Why do you think it does not work?

Re: BLE Security Passcode

Posted: Sat Jun 06, 2020 6:08 pm
by vs_slavchev
Hi chegewara, could you explain in a bit more detail where to use this or the idf demo? I am having the same troubles as the others.

Thanks for all your efforts btw!

Re: BLE Security Passcode

Posted: Tue Jun 09, 2020 1:18 am
by chegewara
If you need arduino with static pass key then take this example and use it. If it not works, then please give us more detail, why its not working, what peer device you are trying to connect with.
If you need esp-idf code here is example:
https://github.com/espressif/esp-idf/bl ... #L555-L575

Re: BLE Security Passcode

Posted: Thu Jun 25, 2020 6:43 pm
by vs_slavchev
I did read the same highlighted lines you mentioned earlier but I don't know where to put them.

What I did is:
in Arduino/libraries/ESP32-BLE-Keyboard I changed the secutiry to:

Code: Select all

  BLESecurity *pSecurity = new BLESecurity();
  pSecurity->setCapability(ESP_IO_CAP_NONE);
  pSecurity->setStaticPIN(123456);
  pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY);
and in packages/esp32/hardware/esp32/1.0.4/libraries/BLE/src I pasted the implementation of the

Code: Select all

void BLESecurity::setStaticPIN(uint32_t pin)
method.

It compiles and uploads to the esp32, but when I try to connect from my android phone to it: a message on the phone pops up and gives me a random 6-digit code and disappears immediately.

I was hoping that setting the capability to ESP_IO_CAP_NONE would make it so I don't need to do any I/O on the esp32 for pairing.

I want to just input a hardcoded pin on the phone to connect to the esp32.

Thanks for your time!

Re: BLE Security Passcode

Posted: Mon Jul 06, 2020 7:22 am
by chegewara
Example with static pin is very simple and it works. All you have to do is to add 2 lines to your code:

Code: Select all

  BLESecurity *pSecurity = new BLESecurity();
  pSecurity->setStaticPIN(123456); 
  
https://github.com/nkolban/esp32-snippe ... ticPIN.ino

Re: BLE Security Passcode

Posted: Fri May 31, 2024 8:48 am
by Drifter22
Hi, I'm successfully BLE Security class with passcode as suggested by chegewara, anyway I need to restart advertising after the disconnection of my client (a smartphone) from my ESP32 devkit C board (server).
When the disconnection event (ondisconnect()) is detected, I restart advertising doing this:

Code: Select all

pServer->startAdvertising();
My problem is that the bonding information seems not retained, because if I try to reconnect the smartphone the server requires a new authentication with password, instead I want to bypass that step because the devices are already bonded.

My sequence:
- provide power supply to the board (server)
- connect with client and request a characteristic read: server requires authentication (OK)
- read characteristic (OK)
- smartphone request disconnection => server restart advertising (OK)
- smartphone try to reconnect and request a characteristic read: server requires authentication (NOK: I want to connect without reauthentication procedure)