'startAdvertising' is not a member of 'BLEDevice

There is a valuable clue in the output you shared previously:

Se encontraron varias bibliotecas para "BLEDevice.h"
  Usado: C:\Users\fimartin\Documents\Arduino\libraries\ArduinoBLE
  No utilizado: C:\Users\fimartin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\BLE

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 include 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.

It appears in this case where Arduino IDE made the wrong decision when discovering the library for the #include <BLEDevice.h> directive. From what I can tell, your sketch is meant to use the "ESP32 BLE Arduino" library that is bundled with the ESP32 boards platform here:

C:\Users\fimartin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.6\libraries\BLE

But Arduino IDE chose the "ArduinoBLE" library instead.

If this is the problem, then the solution will be to influence the library discovery system to pick the intended 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.

The file BLE2902.h looks promising for this purpose since it is not present in the "ArduinoBLE" library and is also unlikely to be present in other libraries since it is fairly unique. Since you already have an #include directive in your sketch for that file, it is only a matter of moving that #include directive up in the sketch to a line above the #include directive for BLEDevice.h.

So change this part of your sketch:

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>

to this:

#include <BLE2902.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

After that, I still get an error when compiling your sketch:

C:\Users\per\AppData\Local\Temp\.arduinoIDE-unsaved202317-14556-f87ec9.adb5o\sketch_feb7a\sketch_feb7a.ino: In function 'void setup()':
C:\Users\per\AppData\Local\Temp\.arduinoIDE-unsaved202317-14556-f87ec9.adb5o\sketch_feb7a\sketch_feb7a.ino:167:19: error: 'nameAndModel' was not declared in this scope
   BLEDevice::init(nameAndModel.c_str());
                   ^~~~~~~~~~~~

but I suspect this is a bug in the sketch code rather than a problem with the libraries. So I think you will be able to solve it.

1 Like