-
Notifications
You must be signed in to change notification settings - Fork 7.6k
How to pair with ESP32 Bluetooth device using passkey/PIN from smartphone? #1458
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
Comments
It depends of some IDF/Bluetooth core functions that aren't available yet... espressif/esp-idf#1541 once it is released, it will be implemented here as well |
I am also working on a Bluetooth device that needs this feature. Is there an estimate on its release date? |
@copercini feature was implemented in commit espressif/esp-idf@8571170 Any idea on when it could be available for esp-idf ? Thank you |
would be great to have this feature. |
Hi, |
I know its not the best solution, but you can try to use esp-idf functions in your app. Just saying. |
Anything more on this? It's a feature i am needing badly. |
No help. Looking forward for support. Thanks |
There is no option to build classic bluetooth with static key pairing (or any key pairing). It is because it requires to change settings in menuconfig. Classic bluetooth can be configured to use SSP (secure simple pairing) or legacy pairing which is controlled in menuconfig. |
Hi everyone,
Open Bluetooth setting in my phone , unpair esp32 device from my old paired list. Rescan for new device then click on the my esp32 device ... Here m the miracle happened .... THE PIN CODE AUTHENTICATION APPEARED .... to pair my Bluetooth esp32 device.... Thanks for all brilliant people who saved my hard work done by providing this solution. Regards |
Thanks for sharing @HarpreetHeera |
Thanks Chegewara ... |
Hi guys. I found some code and I uploaded my repository. |
Its wonderfully working. Thanks |
https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/BLESecurity.cpp#L67 Its here over a year, and its working, just for some reasons is not updated in arduino-essp32. BTW this issue was about PIN in classic BT, not BLE |
Thanks Chegewara, Thanks for your efforts. Great to know. Now we are able to do more stuff on latest release . Thanks again. |
So... I've tried Bluetooth classic serial on the ESP32 and pairing does not work for me with Ubuntu 19.10. The ESP32 always connects and directly disconnects again. Is this the same problem? What can I do about it?
What does that mean? |
sir, can you please provide me the code to set password for esp-32 classic Bluetooth. |
What specific problem are you facing? Need little explanation. |
I am unable to set a paring password for esp32 board. The board is automatically getting connected to mobile phone without asking for any passkey. |
I am in need of help regarding setting passkey for ESP-32 classic Bluetooth please somebody help me out. |
You need to use arduino as component and to change some settings in bluetooth menuconfig or rebuild bluetooth library in esp-idf with new settings and replace the one in arduino. |
Hi,I´m also needing to set a passkey to classic Bluetooth .Use arduino as a component?How can we do that?I´m learning ,please help!Thanks. |
Thanks for the answer.But is it possible to make it easier?How can a simple thing like this give so much work.I don´t know how to do it .Can you help? |
I am also in need of it very much. Please help me out. |
If you are still not able to figure out with latest update. |
Thanks for reply ,but I´m designing a commercial product with possible future updates so I can´t depend on older releases of arduino.I want something that I can work in the future . |
This is part of the solution:
I haven't figured out how to sync the code between device and phone... The code displayed on the phone is not as set above, and pairing fails. Anyone? |
I found this but it's not quite working either... |
This is BLE not BT Classic. But thanks! I may use it anyway... :) PS Needs NimBLE-Arduino library. See https://github.com/h2zero/NimBLE-Arduino |
Is this ever going to be addressed for BlueTooth Serial ? Not being able to set a pass code makes it not usable for a large number of applications :( |
Bump |
1 similar comment
Bump |
I want to setup a pin too. Did you tried this for an incomming connection on classic bluetooth over the AT-command. |
Sorry, It's not the latest version.
This is... |
I could not access the AT-command over serial monitor in the Arduino IDE. It could maybe be possible by using the UART pins of the bluetooth. To do that you need to config ESP-IDF with python. So I followed the instruction here and it worked. |
And I reflash the firmware with 2.1 too. |
@podaen Hi, Could you provide a few more detail on how you managed to achieve this ? Cheers |
The one I flashed doesn't solve the issue here. Just for you to know. Anyway you can downloaded the "downoad tool" and "bin file" from espressif server, unzip it and direct the tool to the bin files. I flashed it on byte 0x1000, 0x8000 and 0x10000. It could be different from ESP to ESP. Google is your friend. |
I found a way to set a fix pin (for what I have test it now) with the last SDK. I did set the SPP (serial port protocol) to true in the menuconfig with python, but it can be already enabled default. I am not sure, after a lot of flashing and reconfiguration. The Arduino precompiled code does support SPP also. I test it on multiple devices and it worked but now I found out it doesn't work with ios like HC05. |
note: In the sdkconfig files the secure simple pairing (SPP) needs to be NOT set. The arduino sdkconfig file that's generated is set for other reasons and can not be edit. So it cannot be done by this libary or any other libary on this type of bluetooth connecting without addapting other sdk files. |
In my eyes secure simple pairing is interesting when you have the capibility too enter a key in both devices. I could be wrong... I m connecting with an android to esp without screen or keyboard. |
alguien lo pudo hacer????.... el codigo pin |
Try calling void setup() {
Serial.begin(115200);
SerialBT.setPin(pin); // setPin() shall come before begin()
SerialBT.begin("ESPBT", true);
Serial.println("The device started in master mode, make sure remote BT device is on!");
connected = SerialBT.connect(address);
if(connected) {
Serial.println("Connected Succesfully!");
} else {
while(!SerialBT.connected(10000)) {
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
}
}
} |
|
I have successfully connected using password 123456 and sending continuous data 0 to 9 in loop and can visible in BLE scanner app in R mode. You can only Read data if your connection is successful. #define SERVICE_UUID "0000FFE0-0000-1000-8000-00805F9B34FB" class MySecurity : public BLESecurityCallbacks { void onPassKeyNotify(uint32_t pass_key) { bool onConfirmPIN(uint32_t pass_key) { bool onSecurityRequest() { void onAuthenticationComplete(esp_ble_auth_cmpl_t cmpl) { class MyCallbacks : public BLECharacteristicCallbacks { BLEServer* pServer = NULL; int counter = 0; void setup() { BLEDevice::init("ESP32"); BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT); BLEDevice::setSecurityCallbacks(new MySecurity()); pServer = BLEDevice::createServer(); void loop() { Serial.print("Sending value: "); delay(1000); // Adjust the delay based on your application requirements // Reset counter when it reaches 9 delay(2000); |
PS. If anyone want's to know how to list and/or remove/delete a BLE Bond/Pair in Arduino, example code is shown below:
|
Hardware:
Board: ESP-WROOM-32
Core Installation/update date: 01/JUN/2018
IDE name: Arduino IDE
Flash Frequency: 80Mhz
Upload Speed: 921600
Description:
I am using the SerialToSerialBT example. I am able to scan and discover the Bluetooth device from my smartphone. But the pairing is without any security/passcode. It simply pairs immediately. How to make the pairing using PIN/Passkey entry?
Sketch:
Debug Messages:
The text was updated successfully, but these errors were encountered: