diff --git a/libraries/SerialBT/examples/BTSerialUppercase/BTSerialUppercase.ino b/libraries/SerialBT/examples/BTSerialUppercase/BTSerialUppercase.ino index c124fcd48..a849fb269 100644 --- a/libraries/SerialBT/examples/BTSerialUppercase/BTSerialUppercase.ino +++ b/libraries/SerialBT/examples/BTSerialUppercase/BTSerialUppercase.ino @@ -22,6 +22,7 @@ #include void setup() { + SerialBT.setName("PicoW UPPERCASE 00:00:00:00:00:00"); SerialBT.begin(); } diff --git a/libraries/SerialBT/keywords.txt b/libraries/SerialBT/keywords.txt index 4579ea83b..567dc23a2 100644 --- a/libraries/SerialBT/keywords.txt +++ b/libraries/SerialBT/keywords.txt @@ -11,6 +11,7 @@ SerialBT KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### +setName KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/libraries/SerialBT/src/SerialBT.cpp b/libraries/SerialBT/src/SerialBT.cpp index f84e05cc3..82a51edb6 100644 --- a/libraries/SerialBT/src/SerialBT.cpp +++ b/libraries/SerialBT/src/SerialBT.cpp @@ -76,7 +76,10 @@ void SerialBT_::begin(unsigned long baud, uint16_t config) { gap_discoverable_control(1); gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); - gap_set_local_name("PicoW Serial 00:00:00:00:00:00"); + if (!_name) { + setName("PicoW Serial 00:00:00:00:00:00"); + } + gap_set_local_name(_name); // Turn on! hci_power_control(HCI_POWER_ON); diff --git a/libraries/SerialBT/src/SerialBT.h b/libraries/SerialBT/src/SerialBT.h index 1d33ca2ba..3f5be856f 100644 --- a/libraries/SerialBT/src/SerialBT.h +++ b/libraries/SerialBT/src/SerialBT.h @@ -37,6 +37,14 @@ class SerialBT_ : public HardwareSerial { SerialBT_(); bool setFIFOSize(size_t size); + bool setName(const char *name) { + if (_running) { + return false; + } + free(_name); + _name = strdup(name); + return true; + } void begin(unsigned long baud = 115200) override { begin(baud, SERIAL_8N1); @@ -82,4 +90,6 @@ class SerialBT_ : public HardwareSerial { volatile int _writeLen = 0; const void *_writeBuff; + + char *_name = nullptr; };