From e1f28982cfe90791f7c4487e9a69a46b4b719c29 Mon Sep 17 00:00:00 2001 From: Holden Karau Date: Sat, 30 Apr 2022 14:48:31 -0700 Subject: [PATCH 1/3] When configured set meshtastic bluetooth name based on owner shortname. --- src/main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 666a59831..9eb1f314d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,8 +97,15 @@ const char *getDeviceName() getMacAddr(dmac); // Meshtastic_ab3c - static char name[20]; - sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]); + static char name[30]; + // If we have an owner shortname and it is short. + if (owner.short_name != NULL + && strlen(owner.short_name) >= 2 + && strlen(owner.short_name) < 10) { + sprintf(name, "Meshtastic_%s", owner.short_name); + } else { + sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]); + } return name; } From ca3192b3dc95f89a17712644ad85c30339f41fca Mon Sep 17 00:00:00 2001 From: Holden Karau Date: Sat, 30 Apr 2022 18:20:41 -0700 Subject: [PATCH 2/3] Clear the existing data before we start advertising --- src/nrf52/NRF52Bluetooth.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nrf52/NRF52Bluetooth.cpp b/src/nrf52/NRF52Bluetooth.cpp index e505e2104..28aa4fea2 100644 --- a/src/nrf52/NRF52Bluetooth.cpp +++ b/src/nrf52/NRF52Bluetooth.cpp @@ -225,6 +225,11 @@ void NRF52Bluetooth::setup() Bluefruit.autoConnLed(false); Bluefruit.begin(); + // Clear existing data. + Bluefruit.Advertising.stop(); + Bluefruit.Advertising.clearData(); + Bluefruit.ScanResponse.clearData(); + // Set the advertised device name (keep it short!) Bluefruit.setName(getDeviceName()); @@ -276,4 +281,4 @@ void NRF52Bluetooth::clearBonds() Bluefruit.Periph.clearBonds(); Bluefruit.Central.clearBonds(); -} \ No newline at end of file +} From 3d3511ceeb8e8646c9bcf3dec46e1fd5f8ff5ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 16 Jun 2022 20:54:50 +0200 Subject: [PATCH 3/3] Change to a different logic --- src/main.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c709f90e2..5efbb841c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,15 +101,14 @@ const char *getDeviceName() getMacAddr(dmac); - // Meshtastic_ab3c - static char name[30]; - // If we have an owner shortname and it is short. - if (owner.short_name != NULL - && strlen(owner.short_name) >= 2 - && strlen(owner.short_name) < 10) { - sprintf(name, "Meshtastic_%s", owner.short_name); + // Meshtastic_ab3c or Shortname_abcd + static char name[20]; + sprintf(name, "%02x%02x", dmac[4], dmac[5]); + // if the shortname exists and is NOT the new default of ab3c, use it for BLE name. + if ((owner.short_name != NULL) && (owner.short_name != name)) { + sprintf(name, "%s_%02x%02x", owner.short_name, dmac[4], dmac[5]); } else { - sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]); + sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]); } return name; }