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:
- Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
- Type
ArduinoBLE
in the "Filter your search..." field. - Scroll down through the list of libraries until you see the "ArduinoBLE" entry.
- Hover the mouse pointer over the "ArduinoBLE" entry.
- You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
A context menu will open. - Select "Remove" from the menu.
An "Uninstall" dialog will open. - Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
The dialog will close. - 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.