ESP32 BLE examples do not compile

Using IDE 2.3.2, ESP32C3 module, win 11

Selecting file>examples>examples for esp32 modules>BLE>client loads sketch client.ino + ci.json
Compiling gets: Many errors ending in Compilation error: 'BLEUUID' does not name a type

Selecting file>examples>examples for esp32 modules>BLE>server loads sketch server.ino + ci.json
Compiling gets: Many errors ending in Compilation error: 'init' is not a member of 'BLEDevice'


Using IDE 1.8.19, ESP32C3 module, win 11

Selecting file>examples>examples from Custom libraries > ESP32 BLE Arduino > BLE_client by unknown & chegewara
Compiling gets: Many errors ending in error...'BLEUUID' does not name a type

Selecting file>examples>examples from Custom libraries > ESP32 BLE Arduino > BLE_server by Kolban
Compiling gets: Many errors ending in error ...'init' is not a member of 'BLEDevice'

Selecting SimpleBlsDevice by espressif Compiles -No errors, but does not suit my needs.


Tried with other ESP boards but no joy. I do not have any Arduinos with BLE.
I have only tried client and server sketches. Need a client that works...

Any and all help appreciated - thanks

I suspect that you're the victim of the latest update of the ESP32 board package.

If you're using version 3.x of the ESP32 board package, I suggest that you roll back to the latest 2.x version and try again.

Note that 3rd party libraries might have been written for an older version of the ESP32 board package and might not have been updated to cater for the breaking changes. You might want to inform the author of that custom library of the issue (usually via github).

These are Examples though. I think they're part of the ESP32 install. It's not just butchalline - and he's rolled back to 2.x to no avail.

Problem with esp32_BleSerial compile - Using Arduino / Programming Questions - Arduino Forum

PE - My version is 2.0.17, without a rollback, and while trying to help I was surprised at nothing Compiling.

BLE Combo failing to compile - Using Arduino / Programming Questions - Arduino Forum

Hi @butchalline.

Are you still experiencing this problem? If so, I'm going to ask you to provide the full verbose output from a compilation.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compile" in the "Preferences" dialog.
  3. Click the "OK" button.
    The "Preferences" dialog will close.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to fail.
  6. You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
  7. Open a forum reply here by clicking the "Reply" button.
  8. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  9. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  10. Move the cursor outside of the code block markup before you add any additional text to your reply.
  11. Click the "Reply" button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here.

Click here for attachment instructions

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the "Reply" button.
  5. Click the "Upload" icon (Upload icon) on the post composer toolbar:
    Upload icon on toolbar
    The "Open" dialog will open.
  6. Select the .txt file you saved from the "Open" dialog.
  7. Click the "Open" button.
    The dialog will close.
  8. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

Thank you for the response. Here are verbose compile errors using:
Boards Manager esp32 by Espressif ver. 2.0.17
ESP32 Dev Module
Arduino IDE 2.3.2

file too big to upload code, so...

First attempt to attach esp32 error.txt using upload icon

esp32 error.txt (897.9 KB)

Second attempt to attach esp32 error.txt using drag and drop

[esp32 error.txt|attachment](upload://vnVfprpdfYtPdubLL24yv6jr8mh.txt) (897.9 KB)


Did I get it right yet?

I think that the upload of your attachment failed.

Thanks for the heads up, sterretje.

OK, great. That makes the cause of the error clear:

Background

Arduino IDE has a "library discovery" system. For each #include directive in the program being compiled, the IDE first checks to see if the file is present in the the compiler's "search path". If not, it then searches through the root source folder of each of the installed libraries to look for a file of that name.

Sometimes multiple libraries contain a file matching the #include directive. In this case, Arduino IDE must decide which of the libraries to use. It has a sophisticated algorithm for picking the best library so it usually makes the right decision, but not always.

Explanation

This is a case where Arduino IDE made the wrong decision when discovering the library for the "Client" example's #include "BLEDevice.h" directive:

A file of that name is present in the "ArduinoBLE" library as well as in the "ESP32 BLE Arduino" library that is bundled with the "esp32" boards platform installation. The IDE chose to use the "ArduinoBLE" library, but the "Client" sketch is meant to use the "ESP32 BLE Arduino" library that is bundled with the "esp32" boards platform.

Solution

There are a couple of possible solutions to this problem. I'll describe them below. You can pick whichever one of the two is most suitable for you:

Uninstall Problematic Library

If you don't actually have any use for the "ArduinoBLE" library, then you can solve the problem by simply uninstalling the library.

I'll provide instructions you can follow to do that:

  1. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
  2. Type ArduinoBLE in the "Filter your search..." field.
  3. Scroll down through the list of libraries until you see the "ArduinoBLE" entry.
  4. Hover the mouse pointer over the "ArduinoBLE" entry.
  5. You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
    A context menu will open.
  6. Select "Remove" from the menu.
    An "Uninstall" dialog will open.
  7. Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
    The dialog will close.
  8. Wait for the uninstall process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully uninstalled library ...

Force Arduino IDE to Choose Correct Library

If you do need the "ArduinoBLE" library for use in other projects then the other solution will not be acceptable.

In this case the solution will be to influence the library discovery system to chose the "ESP32 BLE Arduino" library over the "ArduinoBLE" library.

As I mentioned before, files from the include search path are always given priority by the library discovery system. Once a library is "discovered", its path is added to the include search path. So if we can cause the "ESP32 BLE Arduino" library to be discovered before Arduino IDE does discovery for the ambiguous BLEDevice.h file, then it not discover the "ArduinoBLE" library. This is accomplished by placing an #include directive for a file unique to the "ESP32 BLE Arduino" library above the ambiguous #include directive.

I will arbitrarily choose the file BLEUUID.h, which is present in the "ESP32 BLE Arduino" library, but not in the "ArduinoBLE" library. Simply add an #include directive for that file above the #include directive for BLEDevice.h in your sketch.

So change this part of your sketch:

#include "BLEDevice.h"

to this:

#include "BLEUUID.h"
#include "BLEDevice.h"

Now try compiling the sketch again. Hopefully this time the error will not occur and everything will work as expected.

I also noticed an unrelated problem:

You have selected Tools > Board > esp32 > ESP32 Dev Module from the Arduino IDE menus. This board definition is for use with boards based on the original ESP32 microcontroller.

However, you have indicated that your board is instead based on the newer ESP32-C3 microcontroller. You can not use the "ESP32 Dev Module" board definition with ESP32-C3-based boards. You must instead select Tools > Board > esp32 > ESP32C3 Dev Module from the Arduino IDE menus when using an ESP32-C3-based board.

1 Like

Many thanks ptillsch,
Deleting the ArduinoBLE library allowed compiling without errors.

You are welcome. I'm glad it is working now.

Regards,
Per