BLE Security Passcode

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE Security Passcode

Postby chegewara » Tue Dec 31, 2019 6:33 pm

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

vs_slavchev
Posts: 2
Joined: Sat Jun 06, 2020 5:44 pm

Re: BLE Security Passcode

Postby vs_slavchev » Sat Jun 06, 2020 6:08 pm

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!

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE Security Passcode

Postby chegewara » Tue Jun 09, 2020 1:18 am

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

vs_slavchev
Posts: 2
Joined: Sat Jun 06, 2020 5:44 pm

Re: BLE Security Passcode

Postby vs_slavchev » Thu Jun 25, 2020 6:43 pm

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!

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE Security Passcode

Postby chegewara » Mon Jul 06, 2020 7:22 am

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

Drifter22
Posts: 3
Joined: Tue May 28, 2024 3:44 pm

Re: BLE Security Passcode

Postby Drifter22 » Fri May 31, 2024 8:48 am

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)

Who is online

Users browsing this forum: Bing [Bot] and 149 guests