From 106de3530dac29a0d21803aa44a11121142d63a0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Sep 2022 10:15:30 -1000 Subject: [PATCH] Add support for parsing the short local name in the tracker (#3854) --- .../components/esp32_ble_tracker/esp32_ble_tracker.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp index f7e51a8ab3..47c1f6022e 100644 --- a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +++ b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp @@ -637,11 +637,17 @@ void ESPBTDevice::parse_adv_(const esp_ble_gap_cb_param_t::ble_scan_result_evt_p // (called CSS here) switch (record_type) { + case ESP_BLE_AD_TYPE_NAME_SHORT: case ESP_BLE_AD_TYPE_NAME_CMPL: { // CSS 1.2 LOCAL NAME // "The Local Name data type shall be the same as, or a shortened version of, the local name assigned to the // device." CSS 1: Optional in this context; shall not appear more than once in a block. - this->name_ = std::string(reinterpret_cast(record), record_length); + // SHORTENED LOCAL NAME + // "The Shortened Local Name data type defines a shortened version of the Local Name data type. The Shortened + // Local Name data type shall not be used to advertise a name that is longer than the Local Name data type." + if (record_length > this->name_.length()) { + this->name_ = std::string(reinterpret_cast(record), record_length); + } break; } case ESP_BLE_AD_TYPE_TX_PWR: {