ESP32 Bluetooth pairs but wont connect.

First time here so excuse me if this is not the right place to post this. I have a fairly complex project that all works perfectly well except for the SerialBT connection. Everything was working fine for several weeks, then the Android phone i was using suddenly stopped connecting. I changed to another phone and exactly the same thing happened to that a few days later. If I change the name of the device, the new name appears on the phone and it does say it's paired, but run any serial app and it wont connect. I'm on my third phone now and that works perfectly on one one of my boards but not another identical one. Phone 2 was a bit hit and miss for a while before it eventually stopped.

I could be wrong but I get the feeling that something is right on the very edge of working and as I'm developing this for use in a commercial application, I can't afford to have units failing with time. Has anyone else experienced issues like this????

Thanks in advance.


All the phones are relatively modern Samsung devices but differing models
Just tried a brand new Nokia and it connected immediately but then phone 3 that was working wont connect! Its almost like the ESP32 is permanently remembering the phones mac address and ignoring all previous devices. Is that possible? Could this be some kind of security feature causing my problems??

Just to be clear about this problem.

Four Android phones A, B, C, D.

Phone A pairs and everything works OK.
Change to phone B
Phone B pairs and everything works OK. Phone A will never be able to connect again.
Change to phone C
Phone C pairs and everything works OK. Phone A and B will never be able to connect again.
Change to phone D
Phone D pairs and everything works OK. Phones A, B & C will never be able to connect again.

This logic cannot possibly be correct.

There is no code involved other than SerialBT.begin();

This logic cannot possibly be correct.

I think you are dead right about that, and it probably isn't true either.

There is no code involved other than SerialBT.begin();

I doubt that as well. If it is true, don't expect to see anything on the phone. That said, no code has anything to do with the main problem, refusing to connect, which may well be at the phone end anyway.

This is most unlikely to be a compatibility issue, most non-BLE phones have been retired by now, it may well be a BLE configuration issue. I can't imagine ESP32 having a sin-bin of recalcitrant phones.

If you haven't run out of phones, you might ascertain that ESP Bluetooth is working in the right mode, i.e. properly set up to do whatever you intend. You might also ensure that the phone software is kosher for BLE operations. You might check the Martyn Currey website for BLE-specific information. It seems pretty clear that you cannot use a BLE device as a drop-in replacement for a plain-vanilla HC-05.

Thanks for the reply Nick.

Just to be clear, I've spent several days now trying to get to the bottom of this and read so much stuff my eyes are giving out. As I say, the serial classic Bluetooth works perfectly in my application which really only sends a few short words or status bytes at a time. While testing I use it either with my own app or the common serial Bluetooth app from the play-store and both of these have worked flawlessly for months. The problem only showed its head when my son visited and tried my system using his phone and after that my phone just wouldn't connect.

Fortunately, I do have an almost unlimited supply of new mobiles to test with and can confirm now after using five different phones that the mystery "blacklisting" is repeatable. I suspect most people use just one device to connect to so may never see this effect. Also, while researching the problem, I read so much from people concerned about security and methods of restricting other users from accessing the connection by encryption or pin numbers etc and was wondering if somehow, something like this is inadvertently coming into play? This is why I ended up testing serial connectivity with literally no code running and just opening the connection. The Bluetooth is working in so much that as soon as it's opened, it sends the latest name assigned to it and allows pairing but as soon as you try and connect it fails.



Not experience there,
but did you see the "BluetoothSerial>bt_remove_paired_devices" sketch in the examples of the IDE?


Thanks for that. It looks like that will absolutely solve my problem. I'd reasoned out it had to be something like this, but finding the information on something this obscure wasn't easy. Who'd have thought there'd be an answer in the example code area.

Thanks again to you both.


I would like to know why this happened in case I, or other future forum readers are looking for the same issue.

This is why I ended up testing serial connectivity with literally no code running and just opening the connection.

That isn't testing the serial connectivity, it is testing Bluetooth connectivity. Serial connectivity can only be tested by running code. You need both, and all you have proven so far is that the power is on.

The Bluetooth is working in so much that as soon as it's opened, it sends the latest name assigned to it and allows pairing but as soon as you try and connect it fails.

Same as above. So, as I understand it, in all cases, phone can see and even pair, with Bluetooth, but you cannot communicate with ESP32. You might not understand that Bluetooth consists of two communication facilities, one is to phone by wireless, and the other to computer by wires.

I don't have any real experience with BLE, but I have, actually rather thankfully, seen the same end result some years ago. Both my phone and tablet could pair with my new HM-10 but there was no way that I could get Arduino to send data. The problem there was that the devices were simply incompatible with BLE, and that BLE could not revert to BT2. End of story. In your case, I guess you can be sure that your plethora of phones are BLE compatible, but your BLE device is not yet compatible with the phone(s), hence my comment above.

Thanks again Nick but please understand that I’m that I’m not a novice experimenter. I’ve been involved in electronics and software development for most of my life, however with Bluetooth, I’m in an area where I have no knowledge and hence my appeal for help.

Now, lets be clear. I’m using classic for backward compatibility and running on an ESP32 There are no problems with the basic Bluetooth serial operation, it works perfectly as does the rest of my code and the problem only comes when a different device connects to it. Even then it still works perfectly, but as soon as this is done, the original phone is effectively blocked from ever connecting again.

My code is no lightweight and runs the ESP32 close to its limits, so to avoid any possibility that it may be involved I simply made the first instruction the open command then put it into a long wait. Here obviously no serial data can be passed (not that I need check, I know it works) but the Bluetooth will pair and connect providing it’s not one of my now five backlisted devices! As for the phones, they’re all dual mode so not a problem.

Anyhow Wawa’s pointer to the demo code shows this to be a genuine issue however having run the code to remove the stored mac addresses, I’m still in the same situation where nothing now connects. I need to allow multiple users to connect to this device (one at a time obviously) without breaking their phones so I really do need to find a solution here. Tomorrow’s another day as they say but, in my case, it’s getting like Groundhog Day!



Did you already try to wipe the whole flash of the ESP,
and did it restore to 'normal' operation (with the accumulating error).


For the benefit of others that might be reading this, here is what it says.

//This example demonstrates reading and removing paired devices stored on the ESP32 flash memory
//Sometimes you may find your ESP32 device could not connect to the remote device despite
//many successful connections earlier. This is most likely a result of client replacing your paired
//device info with new one from other device. The BT clients store connection info for paired devices,
//but it is limited to a few devices only. When new device pairs and number of stored devices is exceeded,
//one of the previously paired devices would be replaced with new one.
//The only remedy is to delete this saved bound device from your device flash memory
//and pair with the other device again.

I ran the code first in view mode and it did list three of the blocked mac addresses. These were then removed but unfortunately the problem still exists with all five phones still refusing to connect. Despite it saying that this may happen after a few devices connect, this seemed to occurred for me after just one other phone was used.

Think about it, you develop a system that is all working fine then someone within Bluetooth range tries to pair with your device. You have no indication of what has happened, your project just dies. This is a serious flaw in SerialBT that would have most scratching their heads.

I have a few less challenging issues to get on with for now and clearly I also need to brush up on Bluetooth protocols. Hopefully by then someone may come along with an alternative solution that works for me.



This version of the Flash Download Tool comes with a simple “Erase” button. This lets you completely erase ESP32 flash memory.

This is something you should do every time you get a fresh ESP module and plan to run your own custom firmware on it.

I wonder why they say that here.


Wiping the flash might get me back to a fresh working system but it won’t prevent this happing again. Just so that you understand my problem, let me explain what I’m trying to achieve.

The project is a taxi interface unit that transfers various sensor information to the driver’s smart phone. It also performs fast real time on chip voice recognition without any reliance on the internet. Everything is working perfectly, but the system needs to work with several different taxi drivers, each with their own mobile devices. I understand there are limits on the number of connections so clearly there is a lot more work to do on this other than just getting past this issue.

BTW I can’t seem to find the flash wiping tool from the info you gave.



BTW I can’t seem to find the flash wiping tool from the info you gave.

Did you see the paragraph that says:

Note that we are not providing a link to the new Download Tool because the link changes rather frequently. You can find the Download Tool on Espressif’s official website. The one download tool supports all of Espressif’s chips (ESP8266 and variants as well).

"Flash Download Tool"


It says use the browser button to set the name and path, but what are they and where are they located?
I don't seem to have any files on my PC that look anything like those in the examples.
I've tried watching several YouTube videos on this and they're all a total waste of time.



This is what I do...
Click the link I gave you.
Unzip the file that's now in your downloads folder (or drag the folder inside the downloaded folder onto your desktop).
Locate the flash_download_tool_3.8.5.exe file in that folder.
rightclick>properties>unblock (otherwise Windows sees it as a threat).
Double-click the flash_download_tool_3.8.5.exe file.
It opens a dos box, and eventually a selection window.

As said, no experience there.

It also performs fast real time on chip voice recognition without any reliance on the internet.

I am interested in how you accomplish this.

Leo Thanks again but I'd already done all that but I'm at a total loss to which files I'm suppose to modify, their names and their locations. I've been doing a bit more reading to try and understand the inner workings but it's heavy going. Fortunately for now, because I have an unlimited supply of new phones I can just use another but this doesn't solve the problem.

To Steve. How do I do it? By getting up early and spending a lot of time in front of the PC. The trick is not looking at how other people do things, otherwise you only end up going down the same path. The easy way is to link to the internet as you can see from the many examples around but for my application I needed instant reactions and for it to consume zero data. I started from scratch using the AtMega328 and managed to get an acceptable working solution but while that chip could perform an FFT function, it just wasn't fast enough to do it in real time and process the results. I tried using external band pass filters to get round this but had too many issues with RF interference from the phone and Bluetooth, plus it took 600 ms for each word. The ESP32 is just about fast enough to perform the tasks I need it to do, but it's all written long hand rather than just gluing a collection of modules together. Quite happy to pass on any tips for you but my code is written for a very specific application that probably wouldn't be suitable for general use without a lot of tinkering.

Just started to play with the ESP32, and I saw that there is an 'erase all flash' option in the IDE.
Tools > Erase Flash: "Only Sketch" > All Flash Content.
You can set it to that once, and upload SPIFFS data, or the sketch, and set it back to "Only sketch" after that.
Might buy you some time to dig deeper.