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: {