Skip to content

Commit 2d44e14

Browse files
committed
add cli option to set custom bluetooth name
1 parent b920e7d commit 2d44e14

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎docs/companion_cli.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,19 @@ Radio parameters are common to all roles and handled by `CommonRadioPrefs`.
413413

414414
---
415415

416+
#### Change BLE name
417+
**Usage:**
418+
- `get ble_name`
419+
- `set ble_name <name>`
420+
- `set ble_name_default`
421+
422+
**Parameters:**
423+
- `name`: New BLE name
424+
425+
**Note:** By default the node name will be used as the BLE name. These commands require a reboot to take effect.
426+
427+
---
428+
416429
### Wifi
417430

418431
#### Get status

‎examples/companion_radio/MyMesh.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,26 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
21542154
sprintf(reply, "> pin is now %06d", _prefs.ble_pin);
21552155
return true;
21562156
}
2157+
if (memcmp(command, "set ble_name ", 13) == 0) {
2158+
if (AdvertDataParser::isValidName(&command[13])) {
2159+
StrHelper::strncpy(_prefs.ble_name, &command[13], sizeof(_prefs.ble_name));
2160+
savePrefs();
2161+
sprintf(reply, "> BLE name is now %s (reboot to apply)", _prefs.ble_name);
2162+
} else {
2163+
strcpy(reply, "Error, bad chars");
2164+
}
2165+
return true;
2166+
}
2167+
if (strcmp(command, "get ble_name") == 0) {
2168+
sprintf(reply, "> %s", _prefs.ble_name[0] ? _prefs.ble_name : _prefs.node_name);
2169+
return true;
2170+
}
2171+
if (strcmp(command, "set ble_name_default") == 0) {
2172+
_prefs.ble_name[0] = 0;
2173+
savePrefs();
2174+
sprintf(reply, "> BLE name reset to %s (reboot to apply)", _prefs.node_name);
2175+
return true;
2176+
}
21572177

21582178
#ifdef ENABLE_WIFI_INTERFACE
21592179
if (memcmp(command, "set wifi.ssid ", 14) == 0) {

‎examples/companion_radio/NodePrefs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class NodePrefs : public ConfigSerializer { // persisted to file
3131
float tx_delay_factor = 0;
3232
float direct_tx_delay_factor = 0;
3333
uint32_t ble_pin = 0;
34+
char ble_name[32] = {0};
3435
uint8_t advert_loc_policy = 0;
3536
uint8_t buzzer_quiet = 0;
3637
uint8_t vibe_quiet = 0;
@@ -216,6 +217,7 @@ class NodePrefs : public ConfigSerializer { // persisted to file
216217
def("defs_nm", _parent->default_scope_name, sizeof(_parent->default_scope_name));
217218
def("defs_key", (void *) _parent->default_scope_key, sizeof(_parent->default_scope_key));
218219
def("pin", _parent->ble_pin);
220+
def("ble_name", _parent->ble_name, sizeof(_parent->ble_name));
219221
def("buzz_q", _parent->buzzer_quiet);
220222
def("vibe_q", _parent->vibe_quiet);
221223
def("auto_add", _parent->autoadd_config); // bitmask for auto-add contacts config

‎examples/companion_radio/main.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void setup() {
215215

216216
// add bluetooth interface
217217
#if defined(BLE_PIN_CODE)
218-
bluetooth_interface.begin(BLE_NAME_PREFIX, the_mesh.getNodePrefs()->node_name, the_mesh.getBLEPin());
218+
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());
219219
interface_manager.addInterface(InterfaceType::Bluetooth, &bluetooth_interface);
220220
#endif
221221

0 commit comments

Comments
 (0)