Skip to content

Commit

Permalink
make BLE device name and SSID the same
Browse files Browse the repository at this point in the history
  • Loading branch information
BluemarkInnovations committed Oct 2, 2022
1 parent 35bcb31 commit 1fffc73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
16 changes: 12 additions & 4 deletions RemoteIDModule/BLE_TX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
19 changes: 13 additions & 6 deletions RemoteIDModule/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ void Parameters::load_defaults(void)
}
}

#define IMIN(a,b) ((a)<(b)?(a):(b))

void Parameters::init(void)
{
load_defaults();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1fffc73

Please sign in to comment.