From 4c7a134e15aa87b15f06255be867d3cb9cc9f95c Mon Sep 17 00:00:00 2001 From: Eve <139727413+netrunnereve@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:14:12 -0500 Subject: [PATCH 1/3] add cli option to set custom bluetooth name --- docs/companion_cli.md | 13 +++++++++++++ examples/companion_radio/MyMesh.cpp | 20 ++++++++++++++++++++ examples/companion_radio/NodePrefs.h | 2 ++ examples/companion_radio/main.cpp | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/companion_cli.md b/docs/companion_cli.md index 87d94b5527..4887d997d3 100644 --- a/docs/companion_cli.md +++ b/docs/companion_cli.md @@ -413,6 +413,19 @@ Radio parameters are common to all roles and handled by `CommonRadioPrefs`. --- +#### Change BLE name +**Usage:** +- `get ble_name` +- `set ble_name ` +- `set ble_name_default` + +**Parameters:** +- `name`: New BLE name + +**Note:** By default the node name will be used as the BLE name. These commands require a reboot to take effect. + +--- + ### Wifi #### Get status diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 1a1bcbe767..d1ba6e130e 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2154,6 +2154,26 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* sprintf(reply, "> pin is now %06d", _prefs.ble_pin); return true; } + if (memcmp(command, "set ble_name ", 13) == 0) { + if (AdvertDataParser::isValidName(&command[13])) { + StrHelper::strncpy(_prefs.ble_name, &command[13], sizeof(_prefs.ble_name)); + savePrefs(); + sprintf(reply, "> BLE name is now %s (reboot to apply)", _prefs.ble_name); + } else { + strcpy(reply, "Error, bad chars"); + } + return true; + } + if (strcmp(command, "get ble_name") == 0) { + sprintf(reply, "> %s", _prefs.ble_name[0] ? _prefs.ble_name : _prefs.node_name); + return true; + } + if (strcmp(command, "set ble_name_default") == 0) { + _prefs.ble_name[0] = 0; + savePrefs(); + sprintf(reply, "> BLE name reset to %s (reboot to apply)", _prefs.node_name); + return true; + } #ifdef ENABLE_WIFI_INTERFACE if (memcmp(command, "set wifi.ssid ", 14) == 0) { diff --git a/examples/companion_radio/NodePrefs.h b/examples/companion_radio/NodePrefs.h index c53879767b..b06ace7a78 100644 --- a/examples/companion_radio/NodePrefs.h +++ b/examples/companion_radio/NodePrefs.h @@ -31,6 +31,7 @@ class NodePrefs : public ConfigSerializer { // persisted to file float tx_delay_factor = 0; float direct_tx_delay_factor = 0; uint32_t ble_pin = 0; + char ble_name[32] = {0}; uint8_t advert_loc_policy = 0; uint8_t buzzer_quiet = 0; uint8_t vibe_quiet = 0; @@ -216,6 +217,7 @@ class NodePrefs : public ConfigSerializer { // persisted to file def("defs_nm", _parent->default_scope_name, sizeof(_parent->default_scope_name)); def("defs_key", (void *) _parent->default_scope_key, sizeof(_parent->default_scope_key)); def("pin", _parent->ble_pin); + def("ble_name", _parent->ble_name, sizeof(_parent->ble_name)); def("buzz_q", _parent->buzzer_quiet); def("vibe_q", _parent->vibe_quiet); def("auto_add", _parent->autoadd_config); // bitmask for auto-add contacts config diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index b6d6643d73..82f2b2364a 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -215,7 +215,7 @@ void setup() { // add bluetooth interface #if defined(BLE_PIN_CODE) - bluetooth_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin()); + bluetooth_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->ble_name[0] ? the_mesh.getNodePrefs()->ble_name : the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin()); interface_manager.addInterface(InterfaceType::Bluetooth, &bluetooth_interface); #endif From 2a53a81e825673b154d831f9940eab5f16e528ad Mon Sep 17 00:00:00 2001 From: Eve <139727413+netrunnereve@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:35:32 -0500 Subject: [PATCH 2/3] use ble.name --- docs/companion_cli.md | 7 +++---- examples/companion_radio/MyMesh.cpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/companion_cli.md b/docs/companion_cli.md index 4887d997d3..d861b81e98 100644 --- a/docs/companion_cli.md +++ b/docs/companion_cli.md @@ -415,14 +415,13 @@ Radio parameters are common to all roles and handled by `CommonRadioPrefs`. #### Change BLE name **Usage:** -- `get ble_name` -- `set ble_name ` -- `set ble_name_default` +- `get ble.name` +- `set ble.name ` **Parameters:** - `name`: New BLE name -**Note:** By default the node name will be used as the BLE name. These commands require a reboot to take effect. +**Note:** By default the node name will be used as the BLE name. If `` is empty the BLE name will be reset to the aforementioned default. These commands require a reboot to take effect. --- diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index d1ba6e130e..91a9c8ab55 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2154,7 +2154,13 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* sprintf(reply, "> pin is now %06d", _prefs.ble_pin); return true; } - if (memcmp(command, "set ble_name ", 13) == 0) { + if (strcmp(command, "set ble.name") == 0) { + _prefs.ble_name[0] = 0; + savePrefs(); + sprintf(reply, "> BLE name reset to %s (reboot to apply)", _prefs.node_name); + return true; + } + if (memcmp(command, "set ble.name ", 13) == 0) { if (AdvertDataParser::isValidName(&command[13])) { StrHelper::strncpy(_prefs.ble_name, &command[13], sizeof(_prefs.ble_name)); savePrefs(); @@ -2164,16 +2170,10 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* } return true; } - if (strcmp(command, "get ble_name") == 0) { + if (strcmp(command, "get ble.name") == 0) { sprintf(reply, "> %s", _prefs.ble_name[0] ? _prefs.ble_name : _prefs.node_name); return true; } - if (strcmp(command, "set ble_name_default") == 0) { - _prefs.ble_name[0] = 0; - savePrefs(); - sprintf(reply, "> BLE name reset to %s (reboot to apply)", _prefs.node_name); - return true; - } #ifdef ENABLE_WIFI_INTERFACE if (memcmp(command, "set wifi.ssid ", 14) == 0) { From 0dbf8f62c351819339542c548f5ca56284db7d77 Mon Sep 17 00:00:00 2001 From: Eve <139727413+netrunnereve@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:10:43 -0500 Subject: [PATCH 3/3] change prefix as well --- docs/companion_cli.md | 2 +- examples/companion_radio/MyMesh.cpp | 8 ++++++-- examples/companion_radio/main.cpp | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/companion_cli.md b/docs/companion_cli.md index d861b81e98..212eb905c3 100644 --- a/docs/companion_cli.md +++ b/docs/companion_cli.md @@ -421,7 +421,7 @@ Radio parameters are common to all roles and handled by `CommonRadioPrefs`. **Parameters:** - `name`: New BLE name -**Note:** By default the node name will be used as the BLE name. If `` is empty the BLE name will be reset to the aforementioned default. These commands require a reboot to take effect. +**Note:** By default the BLE name is `Meshcore-` followed by the node name. If `` is empty the BLE name will be reset to the aforementioned default. These commands require a reboot to take effect. --- diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 91a9c8ab55..cd6966e8a6 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2157,7 +2157,7 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* if (strcmp(command, "set ble.name") == 0) { _prefs.ble_name[0] = 0; savePrefs(); - sprintf(reply, "> BLE name reset to %s (reboot to apply)", _prefs.node_name); + sprintf(reply, "> BLE name reset to %s%s (reboot to apply)", BLE_NAME_PREFIX, _prefs.node_name); return true; } if (memcmp(command, "set ble.name ", 13) == 0) { @@ -2171,7 +2171,11 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* return true; } if (strcmp(command, "get ble.name") == 0) { - sprintf(reply, "> %s", _prefs.ble_name[0] ? _prefs.ble_name : _prefs.node_name); + if (_prefs.ble_name[0]) { + sprintf(reply, "> %s", _prefs.ble_name); + } else { + sprintf(reply, "> %s%s", BLE_NAME_PREFIX, _prefs.node_name); + } return true; } diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 82f2b2364a..3e7ec6dcf5 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -215,7 +215,13 @@ void setup() { // add bluetooth interface #if defined(BLE_PIN_CODE) - bluetooth_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->ble_name[0] ? the_mesh.getNodePrefs()->ble_name : the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin()); + char *prefix = BLE_NAME_PREFIX; + char *ble_name = the_mesh.getNodePrefs()->node_name; + if (the_mesh.getNodePrefs()->ble_name[0]) { + prefix = ""; + ble_name = the_mesh.getNodePrefs()->ble_name; + } + bluetooth_interface.begin((const char *) prefix, ble_name, the_mesh.getBLEPin()); interface_manager.addInterface(InterfaceType::Bluetooth, &bluetooth_interface); #endif