From 1fffc73d41b163c69d3619f21b9aa551c4ef181b Mon Sep 17 00:00:00 2001 From: Roel Schiphorst Date: Sun, 2 Oct 2022 15:34:16 +0200 Subject: [PATCH] make BLE device name and SSID the same --- RemoteIDModule/BLE_TX.cpp | 16 ++++++++++++---- RemoteIDModule/parameters.cpp | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/RemoteIDModule/BLE_TX.cpp b/RemoteIDModule/BLE_TX.cpp index 9092822..9cb156f 100644 --- a/RemoteIDModule/BLE_TX.cpp +++ b/RemoteIDModule/BLE_TX.cpp @@ -151,10 +151,18 @@ bool BLE_TX::transmit_legacy_name(ODID_UAS_Data &UAS_data) //set BLE name uint8_t legacy_name_payload[36]; char legacy_name[28] {}; - const char *UAS_ID = (const char *)UAS_data.BasicID[0].UASID; - const uint8_t ID_len = strlen(UAS_ID); - const uint8_t ID_tail = IMIN(4, ID_len); - snprintf(legacy_name, sizeof(legacy_name), "ArduRemoteID_%s", &UAS_ID[ID_len-ID_tail]); + + //fall back options for BLE device name. If the uas_id is not set, use the 4 chars from the MAC address instead + if (strlen(g.uas_id) == 0) { + uint8_t mac[6] {}; + esp_read_mac(mac, ESP_MAC_WIFI_STA); + snprintf(legacy_name, sizeof(legacy_name), "RID_02x%02x", + mac[4], mac[5]); + } else { + const uint8_t ID_len = strlen(g.uas_id); + const uint8_t ID_tail = IMIN(4, ID_len); + snprintf(legacy_name, sizeof(legacy_name), "RID_%s", &g.uas_id[ID_len-ID_tail]); + } memset(legacy_name_payload, 0, sizeof(legacy_name_payload)); const uint8_t legacy_name_header[] { 0x02, 0x01, 0x06, uint8_t(strlen(legacy_name)+1), ESP_BLE_AD_TYPE_NAME_SHORT}; diff --git a/RemoteIDModule/parameters.cpp b/RemoteIDModule/parameters.cpp index 66bcd3c..ce34e02 100644 --- a/RemoteIDModule/parameters.cpp +++ b/RemoteIDModule/parameters.cpp @@ -266,6 +266,8 @@ void Parameters::load_defaults(void) } } +#define IMIN(a,b) ((a)<(b)?(a):(b)) + void Parameters::init(void) { load_defaults(); @@ -298,13 +300,18 @@ void Parameters::init(void) } } } - + //fall back options for ssid. If the uas_id is not set, use the 4 chars from the MAC address instead if (strlen(g.wifi_ssid) == 0) { - uint8_t mac[6] {}; - esp_read_mac(mac, ESP_MAC_WIFI_STA); - snprintf(wifi_ssid, 20, "RID_%02x%02x%02x%02x%02x%02x", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - + if (strlen(g.uas_id) == 0) { + uint8_t mac[6] {}; + esp_read_mac(mac, ESP_MAC_WIFI_STA); + snprintf(wifi_ssid, 20, "RID_02x%02x", + mac[4], mac[5]); + } else { + const uint8_t ID_len = strlen(g.uas_id); + const uint8_t ID_tail = IMIN(4, ID_len); + snprintf(wifi_ssid, 20, "RID_%s", &g.uas_id[ID_len-ID_tail]); + } } if (g.done_init == 0) {