Hello everyone, I’m Yudi. I’m learning ESP32 programming techniques for BLE Server and BLE Client. I found an interesting example to study, which is the following link :
In the sketch for the BLE Server, it works normally. As explained in the link, the BLE Server sketch is tested using a cell phone by downloading the Android app 'nRF Connect for Mobile.' And there is visible temperature and humidity data being read on the Serial Monitor.
However, when the BLE Client is run, the BLE Server board freezes (hang), as indicated by the absence of temperature and humidity data being sent to the Serial Monitor. The connection between the BLE Server and BLE Client is established briefly, but then both devices freeze. There is no temperature and humidity data received by the ESP32 Client, which should be displayed on the Serial Monitor and also shown on the SSD1306 OLED display module.
Is there a bug in the sketch for the ESP32 Client? Please help me find the bugs, I haven't been able to find them for 2 days.
Please post ALL code in code tags. Also post any error log in code tags.
BTW, just saying 'help me find the bugs' is NOT likely going to attract much attention.
Yes, I saw the error message, but I don't know the exact meaning of it and I don't know which line in the ESP32 BLE Client sketch is causing the error.
Please help me so that the ESP32 BLE Client can receive data from the ESP32 BLE Server.
Your BLE Client might be crashing the ESP32 Server due to connection handling or data reception issues. First, check the watchdog timer—if the ESP32 freezes, it could be stuck in a loop. Debug logs can help pinpoint where it stops. BLE operations are memory-intensive, so ensure there’s enough heap available. Also, improper handling of disconnect events or read errors can cause crashes. Try adding small delays between connection attempts and data reads to prevent overload. If both devices freeze, unstable power might be the culprit. Have you tested with a minimal setup or checked debug output? Sharing your client-side code could help pinpoint the issue!
@yudilubis GOOD CATCH. I don't know for sure if that is the cause, but it is an error.
NOTE to @yudilubis add a return (true) ; as the last line of the connectToServer function. Post the changed code in code tags so we can verify the change is correct.
YES. That 'right words' WAS 100% art or luck or in my case perseverance, but I think AI may actually be useful in the AI trying various search phrases from our AI request. I have started using much longer search phrases and when I see google beginning to reply with an AI result I know I am likely going to learn something. I think my new approach works at least 75% of the time.
Thank you Sonofcy and ec2021. I tried many things last night based on your suggestions, including commenting out all the Serial.print() function lines. It worked as expected for a while, and I was happy. But when I tried to open each Serial.print() function one by one, the client and server froze again. Strange. I closed the Serial.print() functions again, but it still froze even though it was working fine earlier.
This morning I tried Sonofcy's suggestion and changed the debug level. I tested it with various options, such as 'error', 'warn', and 'verbose', and the result provided the following information:
Even though I commented out all the Serial.print() functions, and commented out lines in the sketch that I thought could be temporarily disabled with '//', the error still appeared.
I don't understand where the mistake is from the project example given by this link:
It’s impossible that they provided a project example with an error.
Dear ec2021, last night I found something odd because the project example I got from the link: ESP32 BLE Server Client Communication using Arduino IDE worked normally when I commented out all the lines in the sketch containing the Serial.print() functions. It worked fine, and I was so happy because I had been puzzled for 10 days wondering why it was freezing.
I was curious, so I uncommented each Serial.print() function one by one. I found that the error happened again on the line where I re-enabled the function. So, I commented it out again with "//". But strangely, the error and freeze still occurred. Finally, I commented out all the Serial.print() function lines again, but the error remained as before.
Why could this be happening? Is there still some instability with the ESP32 WROOM 32D board I’m using, or could there still be bugs in some of the libraries being used?
It is important when you change a sketch; you save it before doing a verify. There have been some recent issues around that phenomenon. I am NOT sure it is true here, but it is a good habit to get into.
Adding the '"return true" is surely ok. In your case it looks like an additional issue with the memory partitioning. That's what the message points to. Did you follow the suggestion that comes with the error message?
I just googled for "text section exceeds' and found this
There are further hits on Google which you may check for possible solutions if this doesn't work.
As I wrote in my last post: It's quite unlikely to be the first to encounter a certain problem. Therefore a thorough search is always a good idea.
Good luck!
ec2021
P S.: This post explains where the partition scheme can be changed in the Arduino IDE (just where you may look, it finally depends on the board you've chosen)