BLE Mouse example compilation error

Hello everyone,

I am trying to compile the BLE Mouse code from the below repo-
BLE mouse repo

The basic code example is -

/**
 * This example turns the ESP32 into a Bluetooth LE mouse that scrolls down every 2 seconds.
 */
#include <BleMouse.h>

BleMouse bleMouse;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  bleMouse.begin();
}

void loop() {
  if(bleMouse.isConnected()) {
    Serial.println("Scroll Down");
    bleMouse.move(0,0,-1);
  }
  delay(2000);
}

The selected board is
XIAO_ESP32C3

I am getting a compilation error-

C:\Users\usr\OneDrive\Documents\Arduino\libraries\ESP32-BLE-Mouse\BleMouse.cpp: In static member function 'static void BleMouse::taskServer(void*)':
C:\Users\usr\OneDrive\Documents\Arduino\libraries\ESP32-BLE-Mouse\BleMouse.cpp:143:37: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'String'
  143 |   BLEDevice::init(bleMouseInstance->deviceName);
      |                   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~
      |                                     |
      |                                     std::string {aka std::__cxx11::basic_string<char>}
In file included from C:\Users\usr\OneDrive\Documents\Arduino\libraries\ESP32-BLE-Mouse\BleMouse.cpp:1:
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLEDevice.h:41:27: note:   initializing argument 1 of 'static void BLEDevice::init(String)'
   41 |   static void init(String deviceName);                                                            // Initialize the local BLE environment.
      |                    ~~~~~~~^~~~~~~~~~
C:\Users\usr\OneDrive\Documents\Arduino\libraries\ESP32-BLE-Mouse\BleMouse.cpp:151:50: error: no matching function for call to 'BLECharacteristic::setValue(std::string&)'
  151 |   bleMouseInstance->hid->manufacturer()->setValue(bleMouseInstance->deviceManufacturer);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLEServer.h:23,
                 from C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLEDevice.h:21:
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:77:8: note: candidate: 'void BLECharacteristic::setValue(uint8_t*, size_t)'
   77 |   void setValue(uint8_t *data, size_t size);
      |        ^~~~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:77:8: note:   candidate expects 2 arguments, 1 provided
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:78:8: note: candidate: 'void BLECharacteristic::setValue(String)'
   78 |   void setValue(String value);
      |        ^~~~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:78:24: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'String'
   78 |   void setValue(String value);
      |                 ~~~~~~~^~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:79:8: note: candidate: 'void BLECharacteristic::setValue(uint16_t&)'
   79 |   void setValue(uint16_t &data16);
      |        ^~~~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:79:27: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'uint16_t&' {aka 'short unsigned int&'}
   79 |   void setValue(uint16_t &data16);
      |                 ~~~~~~~~~~^~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:80:8: note: candidate: 'void BLECharacteristic::setValue(uint32_t&)'
   80 |   void setValue(uint32_t &data32);
      |        ^~~~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:80:27: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'uint32_t&' {aka 'long unsigned int&'}
   80 |   void setValue(uint32_t &data32);
      |                 ~~~~~~~~~~^~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:81:8: note: candidate: 'void BLECharacteristic::setValue(int&)'
   81 |   void setValue(int &data32);
      |        ^~~~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:81:22: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'int&'
   81 |   void setValue(int &data32);
      |                 ~~~~~^~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:82:8: note: candidate: 'void BLECharacteristic::setValue(float&)'
   82 |   void setValue(float &data32);
      |        ^~~~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:82:24: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'float&'
   82 |   void setValue(float &data32);
      |                 ~~~~~~~^~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:83:8: note: candidate: 'void BLECharacteristic::setValue(double&)'
   83 |   void setValue(double &data64);
      |        ^~~~~~~~
C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE\src/BLECharacteristic.h:83:25: note:   no known conversion for argument 1 from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'double&'
   83 |   void setValue(double &data64);
      |                 ~~~~~~~~^~~~~~
Using library ESP32-BLE-Mouse at version 0.3.1 in folder: C:\Users\usr\OneDrive\Documents\Arduino\libraries\ESP32-BLE-Mouse 
Using library BLE at version 2.0.0 in folder: C:\Users\usr\OneDrive\Documents\ArduinoData\packages\esp32\hardware\esp32\3.0.0\libraries\BLE 
exit status 1
Error compiling for board XIAO_ESP32C3.

I'd appreciate your help resolving this.
Thanks in ad

Hi @abiswas9327.

Explanation

There are significant breaking changes in the recently released version 3.0.0 of the "esp32" boards platform.

Some of these breaking changes caused a loss of compatibility with the "ESP32 BLE Mouse" library:

https://github.com/espressif/arduino-esp32/blob/master/docs/en/migration_guides/2.x_to_3.0.rst#changes-in-apis

BLE

Changes in APIs

  • Changed APIs return and parameter type from std::string to Arduino style String.
  • Changed UUID data type from uint16_t to BLEUUID class.
  • BLEScan::start and BLEScan::getResults methods return type changed from BLEScanResults to BLEScanResults*.

I see that a community member did submit a fix for the breakage, which unfortunately has not yet been accepted by the library author:

Resolution

There are a couple of alternative ways this could be resolved. I'll describe both options. You can pick whichever one of them you prefer:


:red_exclamation_mark: Pick and perform only one of the two fixes. You don't need to perform both of them.


Use the patched version of the library

As I mentioned above, a community member has already updated the library to be compatibility with version 3.0.0 of the "esp32" platform. So you can solve the problem by uninstalling the incompatible standard version you have installed currently and then installing the modified version of the library that has the proposed fix.

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

  1. Select File > Quit (or Arduino > Quit Arduino for macOS users) from the Arduino IDE menus if it is running.
    All Arduino IDE windows will close.
  2. Using your file manager (e.g., Windows "File Explorer"), delete the folder at the following path:
    C:\Users\usr\OneDrive\Documents\Arduino\libraries\ESP32-BLE-Mouse
    
    :warning: Please be careful when deleting things from your computer. When in doubt, back up!
  3. Start Arduino IDE.
  4. Click the following link to open the homepage of the GitHub repository for the patched version of the library in your web browser:
    https://github.com/sirfragles/ESP32-BLE-Mouse/tree/dev
  5. Click the "Code ▾" button you see on that page.
  6. Select Download ZIP from the menu.
    A download of the ZIP file of the library will start.
  7. Wait for the download to finish.
  8. Select Sketch > Include library > Add .ZIP Library from the Arduino IDE menus.
  9. Select the downloaded file.
  10. Click the "Open" button.
  11. Wait for the message to appear on the teal bar in the Arduino IDE Window:

    Library added to your libraries. Check "Include library" menu

Now compile your sketch again. Hopefully this time the error will not occur and the library will work as expected.


After testing this modified version of the library in your project, it will be helpful for you to add a comment or review describing the results of your testing on the pull request where the fix is being proposed. This feedback can facilitate the acceptance of the fix into the library (or if you discover defects in the proposed chnages, bring them to the attention of the contributor).


Use compatible version of "esp32" platform

The breaking changes in the "esp32" boards platform were introduced in the 3.0.0 release, so you won't have these problems compiling the library if you install an older version of the "esp32" platform.

  1. Select Tools > Board > Boards Manager... from the Arduino IDE menus.
    The "Boards Manager" dialog will open.
  2. Wait for the updates to finish, as shown by the messages printed at the bottom of the "Boards Manager" dialog.
  3. Scroll down through the list of boards platforms until you find the "esp32" entry. Click on it.
    A "Select version" dropdown will appear in the entry.
  4. Click on the "Select version" dropdown.
    It will expand.
  5. Select "2.0.17" from the menu.
  6. Click the "Install" button in the "esp32" entry.
  7. Wait for the installation to finish.
  8. Click the "Close" button on the "Boards Manager" dialog.
    The "Boards Manager" dialog will close.

Now compile your sketch again. Hopefully this time the error will not occur and the library will work as expected.


Arduino IDE will occasionally notify you that a new version of the boards platform is available, you'll need to refrain from accepting the offer that will cause an update back to the problematic version of the platform. If you find these notifications annoying, you can disable them via the IDE preferences.

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

  1. Select File > Preferences... (or Arduino > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Uncheck the box next to "Check for updates on startup" in the "Preferences" dialog.
  3. Click the "OK" button.
    The "Preferences" dialog will close.

If you disable the automatic update check, make sure to periodically do a manual check for newer versions of the installed boards platforms and libraries that you want to keep updated. You can check for new versions of Arduino IDE by selecting Help > Check for Arduino IDE Updates from the Arduino IDE menus. You can check for new versions of boards platforms and libraries by selecting "Updatable" from the "Type" menu in the Boards Manager and Library Manager views.

1 Like

It worked like a charm.

Thanks a lot :slight_smile:

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

Regards,
Per

thank you so much.. :sneezing_face: :heart: literally i waste my 2 hours on this error

1 Like

Some for me. So a big thanks from me too.

1 Like