From c17e38e58f70fc116ed6e2bd313ff8eada07cb54 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 27 Sep 2025 13:39:03 -0500 Subject: [PATCH] order matters --- esphome/components/esp32_ble/ble.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/esphome/components/esp32_ble/ble.cpp b/esphome/components/esp32_ble/ble.cpp index 2108ded472..64cef70de2 100644 --- a/esphome/components/esp32_ble/ble.cpp +++ b/esphome/components/esp32_ble/ble.cpp @@ -81,8 +81,17 @@ void ESP32BLE::advertising_set_service_data_and_name(std::span da // when changing both properties, avoiding the brief gap that would occur with separate calls. this->advertising_init_(); - this->advertising_->set_service_data(data); - this->advertising_->set_include_name(include_name); + + if (include_name) { + // When including name, clear service data first to avoid packet overflow + this->advertising_->set_service_data(std::span{}); + this->advertising_->set_include_name(true); + } else { + // When including service data, clear name first to avoid packet overflow + this->advertising_->set_include_name(false); + this->advertising_->set_service_data(data); + } + this->advertising_start(); }