From ed5d8a2cb88093db10cc2d3e28e56b35b0420d5a Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Thu, 1 Jan 2026 14:48:24 -0500 Subject: [PATCH] =?UTF-8?q?Make=20string=20use=20compatible=20with=20newer?= =?UTF-8?q?=20ESP-Arduino=20core=E2=80=99s=20BLEDevice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In espressif/arduino-esp32 822f252b353c (2023-10-06), first released in arduino-esp32 3.0.0 (2024-05-27), some string types in BLEDevice changed from std::string (a C++ library string) to String (an Arduino string). See https://github.com/espressif/arduino-esp32/pull/8724. This change makes BleKeyboard compatible with both the old and new versions of arduino-esp32, by detecting the version in use at compile time. --- BleKeyboard.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BleKeyboard.cpp b/BleKeyboard.cpp index 48a8930..ce5f115 100644 --- a/BleKeyboard.cpp +++ b/BleKeyboard.cpp @@ -103,7 +103,11 @@ BleKeyboard::BleKeyboard(std::string deviceName, std::string deviceManufacturer, void BleKeyboard::begin(void) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 BLEDevice::init(deviceName); +#else + BLEDevice::init(String(deviceName.c_str(), deviceName.size())); +#endif BLEServer* pServer = BLEDevice::createServer(); pServer->setCallbacks(this); @@ -114,7 +118,11 @@ void BleKeyboard::begin(void) outputKeyboard->setCallbacks(this); +#if ESP_ARDUINO_VERSION_MAJOR < 3 hid->manufacturer()->setValue(deviceManufacturer); +#else + hid->manufacturer()->setValue(String(deviceManufacturer.c_str(), deviceManufacturer.size())); +#endif hid->pnp(0x02, vid, pid, version); hid->hidInfo(0x00, 0x01);