T-vK / ESP32-BLE-Keyboard

Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
2.47k stars 415 forks source link

Fixed a compilation issue in Arduino ide #315

Open AJIN-98 opened 3 months ago

AJIN-98 commented 3 months ago
In member function 'void BleKeyboard::begin()':
c:\Users\achu\Documents\Arduino\libraries\ESP32_BLE_Keyboard\BleKeyboard.cpp:106:19: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'String'
  106 |   BLEDevice::init(deviceName);
      |                   ^~~~~~~~~~
      |                   |
      |                   std::string {aka std::__cxx11::basic_string<char>}
In file included from c:\Users\achu\Documents\Arduino\libraries\ESP32_BLE_Keyboard\BleKeyboard.cpp:9:
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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\achu\Documents\Arduino\libraries\ESP32_BLE_Keyboard\BleKeyboard.cpp:117:32: error: no matching function for call to 'BLECharacteristic::setValue(std::string&)'
  117 |   hid->manufacturer()->setValue(deviceManufacturer);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLEHIDDevice.h:17,
                 from c:\Users\achu\Documents\Arduino\libraries\ESP32_BLE_Keyboard\BleKeyboard.h:24,
                 from c:\Users\achu\Documents\Arduino\libraries\ESP32_BLE_Keyboard\BleKeyboard.cpp:1:
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLECharacteristic.h:77:8: note:   candidate expects 2 arguments, 1 provided
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLECharacteristic.h:78:8: note: candidate: 'void BLECharacteristic::setValue(String)'
   78 |   void setValue(String value);
      |        ^~~~~~~~
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLECharacteristic.h:79:8: note: candidate: 'void BLECharacteristic::setValue(uint16_t&)'
   79 |   void setValue(uint16_t &data16);
      |        ^~~~~~~~
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLECharacteristic.h:80:8: note: candidate: 'void BLECharacteristic::setValue(uint32_t&)'
   80 |   void setValue(uint32_t &data32);
      |        ^~~~~~~~
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLECharacteristic.h:81:8: note: candidate: 'void BLECharacteristic::setValue(int&)'
   81 |   void setValue(int &data32);
      |        ^~~~~~~~
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLECharacteristic.h:82:8: note: candidate: 'void BLECharacteristic::setValue(float&)'
   82 |   void setValue(float &data32);
      |        ^~~~~~~~
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\libraries\BLE\src/BLECharacteristic.h:83:8: note: candidate: 'void BLECharacteristic::setValue(double&)'
   83 |   void setValue(double &data64);
      |        ^~~~~~~~
C:\Users\achu\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.3\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);
      |                 ~~~~~~~~^~~~~~

exit status 1

Compilation error: exit status 1
erikpendragon commented 3 months ago

I made the changes manually, and it worked for me. Thank you.

Grahack commented 3 months ago

Hi, doesn't work for me. I get:

/home/chri/Arduino/libraries/ESP32-BLE-Keyboard/BleKeyboard.cpp: In member function 'void BleKeyboard::begin()':
/home/chri/Arduino/libraries/ESP32-BLE-Keyboard/BleKeyboard.cpp:106:38: error: 'c_str' was not declared in this scope; did you mean 'wcsstr'?
  106 |   BLEDevice::init(String(deviceName, c_str()));
      |                                      ^~~~~
      |                                      wcsstr

exit status 1

Compilation error: exit status 1

Pro tip: enclose your code between triple ticks ``` for your code or error messages to display correctly.

Grahack commented 3 months ago

~Works for me. Many thanks.~ See below.

Grahack commented 3 months ago

OOOOOOPS sorry I thought I was posting «works for me» in this PR: https://github.com/T-vK/ESP32-BLE-Keyboard/pull/303. I indeed get the error I posted above.