[esp32_ble] Store device name in flash to reduce RAM usage

This commit is contained in:
J. Nick Koston
2025-11-23 20:36:54 -06:00
parent c91a9495e6
commit e7d09c0f62
2 changed files with 4 additions and 5 deletions

View File

@@ -257,8 +257,8 @@ bool ESP32BLE::ble_setup_() {
#endif
std::string name;
if (this->name_.has_value()) {
name = this->name_.value();
if (this->name_ != nullptr) {
name = this->name_;
if (App.is_name_add_mac_suffix_enabled()) {
// MAC address suffix length (last 6 characters of 12-char MAC address string)
constexpr size_t mac_address_suffix_len = 6;

View File

@@ -112,7 +112,7 @@ class ESP32BLE : public Component {
void loop() override;
void dump_config() override;
float get_setup_priority() const override;
void set_name(const std::string &name) { this->name_ = name; }
void set_name(const char *name) { this->name_ = name; }
#ifdef USE_ESP32_BLE_ADVERTISING
void advertising_start();
@@ -191,8 +191,7 @@ class ESP32BLE : public Component {
esphome::LockFreeQueue<BLEEvent, MAX_BLE_QUEUE_SIZE> ble_events_;
esphome::EventPool<BLEEvent, MAX_BLE_QUEUE_SIZE> ble_event_pool_;
// optional<string> (typically 16+ bytes on 32-bit, aligned to 4 bytes)
optional<std::string> name_;
const char *name_{nullptr};
// 4-byte aligned members
#ifdef USE_ESP32_BLE_ADVERTISING