Skip to content

Commit 1f9350d

Browse files
Allow setting SerialBT advertised name (#2181)
Trivial fix #2179
1 parent 361b4e0 commit 1f9350d

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

libraries/SerialBT/examples/BTSerialUppercase/BTSerialUppercase.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <SerialBT.h>
2323

2424
void setup() {
25+
SerialBT.setName("PicoW UPPERCASE 00:00:00:00:00:00");
2526
SerialBT.begin();
2627
}
2728

libraries/SerialBT/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SerialBT KEYWORD1
1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
14+
setName KEYWORD2
1415

1516
#######################################
1617
# Constants (LITERAL1)

libraries/SerialBT/src/SerialBT.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ void SerialBT_::begin(unsigned long baud, uint16_t config) {
7676

7777
gap_discoverable_control(1);
7878
gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO);
79-
gap_set_local_name("PicoW Serial 00:00:00:00:00:00");
79+
if (!_name) {
80+
setName("PicoW Serial 00:00:00:00:00:00");
81+
}
82+
gap_set_local_name(_name);
8083

8184
// Turn on!
8285
hci_power_control(HCI_POWER_ON);

libraries/SerialBT/src/SerialBT.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class SerialBT_ : public HardwareSerial {
3737
SerialBT_();
3838

3939
bool setFIFOSize(size_t size);
40+
bool setName(const char *name) {
41+
if (_running) {
42+
return false;
43+
}
44+
free(_name);
45+
_name = strdup(name);
46+
return true;
47+
}
4048

4149
void begin(unsigned long baud = 115200) override {
4250
begin(baud, SERIAL_8N1);
@@ -82,4 +90,6 @@ class SerialBT_ : public HardwareSerial {
8290

8391
volatile int _writeLen = 0;
8492
const void *_writeBuff;
93+
94+
char *_name = nullptr;
8595
};

0 commit comments

Comments
 (0)