-
Notifications
You must be signed in to change notification settings - Fork 710
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
BLE client gets stuck while calling BLEClient::connect() #874
Comments
Same issue here. I noticed that after a reset on the client this happens, after resetting once or twice again it reconnects. |
It can be few reasons, but if i would have to guess its because in arduino version there is still few bugs. My advice is to use this library instead, or to find someone who will update arduino version. |
I am having the same issue. |
Please excuse for my silence, I have stopped working on the esp-32 (a little bit out of frustration) to concentrate on the other chip im working on. This morning I wanted to try again from the beginning and simply copy pasted the client example in the "ESP32 BLE Arduino" library (that I have tried before without success) and changed up the Uuids to match my other chip's Uuids. I gave it a go and it...connected successfully without trouble... If there is one thing I know it's that the problem dosen't seem to come from the libraries (since it worked), but I can't know for sure. |
Hi! Any ideas how to fix this? |
@majstor12 yes, use this repository instead of arduino library. In arduino library is some bug that has been fixed here long time ago (few other bugs too). |
Do we expect to have these changes/improvements propagated to arduino library and how? |
@chegewara Might be a silly question, how can I use this repository instead of arduino library? Can you please teach me how to do that? |
@chegewara Thanks :) |
Hi, I have got the same problem Thanks. |
Thanks for sharing your hang workaround. Instead of 60000 I'm using 15000; The smaller value works well for me (shorter "hang" times).
|
Thanks for your notice, Thomas. |
@jiangminghe During validation I found another xSemaphoreTake() that caused an endless hang in my client application. This required another workaround patch at line 198: I changed the timeout to 15 seconds, as follows: I recognize that these edits are workarounds, not permanent patches. But I will use them until the semaphore issues are resolved.
|
Patch that is fixing semaphores issue has been added to arduino-esp32 repository some time ago. |
I'm using the latest arduino-esp32 repository (last patch was from about 30 days ago). If there are more recent semaphore fixes then I would definitely want to try them out.
|
Sorry, it was the latest one, in this case there is somewhere else semaphore that causing stuck. |
I tried replacing the libraries as suggested by @chegewara , I see no change. The program still gets stuck. |
Hi, I am having this issue as well: `bool connectToServer() {
//**** MANY TIMES, DOES NOT EXECUTE CODE BELOW ****//
}` Any new updates, @chegewara? |
It is possible that calling this line:
Also changing semaphore to timed semaphore as many times was suggested is good idea. |
Ok thanks I'll try the timed semaphore fix. |
You can not connect while scanning. Stop scanning first. |
While reading #757 I have found that |
@ravsten There is overloaded connect function, which will figure out address type, but you need to pass advertised device instead of address. |
To avoid misleading anyone I want to mention that I am using an Arduino built-in BLE ESP32 library so I guess that is why I pass BLEAddress instead of BLEDevice. Correct @chegewara? |
Hello, could you share with us how to do it? :) |
Hi I'm having the same issue here. I'm trying to connect 2 ESP32, one as a Client and the other one as a Server. I'm using the Arduino library. |
I edited the FreeRTOS.cpp file, changing the |
Check the file again and confirm you have changed ALL the occurrences of xSemaphoreTake() that used the portMAX_DELAY to 15000UL. If you've already done that then I doubt your issue is due to the semaphore timeout hang issue.
|
Hello, I am facing the same stuck whenever trying to connect to the fourth server. Is there any chance to connect to more than 3 servers? |
Do not attempt to Connect to a BLE Server before the call to You need to initiate the scan, on your Once the scan call returns (as stated in the first line of this response) you can then connect to this |
Hi There, i have same problem in connecting to peripheral. It's always stuck on connect command line. I also have already try Mr. Andreas Polar Receiver example but that has same stuck too. I use ESP32 pico kit. Here's my demo code. Does anyone have a solution for this issue? I will be grateful if you could help me.
And Here's my output from Serial monitor.
|
There is second parameter in connect function: |
@chegewara: and this solves the stuck? In the meanwhile and as a workaround I am using the other CORE for any BLE connect tasks. |
Im not sure it will solve, but it was the reason in many other cases. Thats why i had to write that second connect function. |
If anyone wants a confirmed-working example of BLE connections for the ESP32 boards... I have a repository as part of my Automatic Discovery & Pairing articles. https://github.com/Flowduino/ESP32_ESP-Now_Pairing You might be able to figure out what you need to change in your own respective codebases from my code in that repository. Enjoy! |
@LK-Simon Thank you I solved the stuck problem and made an example about it. Those who have problems with Connect can try this example. https://github.com/MertGurdogann/BLEconnectExample/blob/main/BLEconnect/BLEconnect.ino Here is example output from Serial Monitor
Best regards. |
From the code i am guesing that another |
Hello,
I am wandering why this 2nd exception(gap event) occurs !
|
This is very nasty error, because its more or less telling that you have error in code somewhere (maybe in library) and this error itself is causing to generate logs or something which is causing another error.
I dont know your code and purpose of it, but is it possible that 2 devices you are trying to connect to have 2 completely different set of services and characteristics? |
Hello Chegewara, |
Then maybe you are trying to read/write characteristic that does not exist on 2nd device, or you do some other stuff that break it, assign new characteristic to pointer. Just test 1 step at a time:
|
My sketch manages only 1 device. But if you want I can adapt it to manage 2. |
No, i dont want you to change your code. I just thought it is how you doing it now. |
After a lot of trial my sketch works only with After that I give you for the 1st device (without any problem). 2nd device:
1st device:
|
Is it possible that MIDI device has more than 1 service with UUID: If you have more esp32, could you try this code to emulate your device and see if your current code still crash: I will try to find some time to do the same, but it would be good to have your code to perform test or at least the part that is performing connection to device. |
Yes it is not the only services : here are the others :
Yes I have a second esp32, and there is no problem with the client with this server sketch. I give you the log below. Because of the perfect connection, not sure that giving you my sketch will help, but I put just below just in case :
|
Instead try to add short delay and check I also advice to use this connect function (there is nothing wrong with your way to do it): If you are not working with arduino it is still possible to use library from it (copy/paste). The code crash exactly here:
and i am suspecting that device you are connecting with is disconnecting for some reason before this code is called. I would start with comment out this code and see whats going on:
|
I have just one thing to say: many many many and many thanks to you Chegewara 👍 . |
First of all, hello and thank you for your libraries and excuse me for this probably very simple question.
Very recently I have begun learning BLE and the esp32 and my goal for the moment is to successully establish a BLE connection between an esp32 (as client) and the nRF52 (as server). I believe the nRF52 works, since I can connect to it using my phone and control the value of characteristics in it. However, I can't get the esp32 to connect to it successully. It is able to scan and detect nearby devices and find the nRF52's adress no problem, but when a connection attempt is made using the connect() function, the program seems to wait indefinitely and no connection is ever established. While I have done some research on semaphores, I am still quite unfamilliar with them.
I wish to understand where it gets stuck in the connect() fuction, why it does that and how can I make it work.
Here is my code (I am using the Arduino framework in PlatformIO):
And here is what the serial monitor looks like:
Do you think you can help me?
Thanks in advance.
The text was updated successfully, but these errors were encountered: