mirror of
https://github.com/esphome/esphome.git
synced 2026-09-20 19:48:39 +00:00
Use PROGMEM for MQTT version format string on ESP8266
Store format string in PROGMEM and copy to RAM buffer on ESP8266 before use. On other platforms, use the format string directly. This saves RAM on ESP8266 while maintaining the same functionality.
This commit is contained in:
@@ -154,8 +154,15 @@ bool MQTTComponent::send_discovery_() {
|
||||
device_info[MQTT_DEVICE_MANUFACTURER] =
|
||||
model == nullptr ? ESPHOME_PROJECT_NAME : std::string(ESPHOME_PROJECT_NAME, model - ESPHOME_PROJECT_NAME);
|
||||
#else
|
||||
device_info[MQTT_DEVICE_SW_VERSION] =
|
||||
str_sprintf(ESPHOME_VERSION " (config hash 0x%08" PRIx32 ")", App.get_config_hash());
|
||||
static const char ver_fmt[] PROGMEM = ESPHOME_VERSION " (config hash 0x%08" PRIx32 ")";
|
||||
#ifdef USE_ESP8266
|
||||
char fmt_buf[sizeof(ver_fmt)];
|
||||
strcpy_P(fmt_buf, ver_fmt);
|
||||
const char *fmt = fmt_buf;
|
||||
#else
|
||||
const char *fmt = ver_fmt;
|
||||
#endif
|
||||
device_info[MQTT_DEVICE_SW_VERSION] = str_sprintf(fmt, App.get_config_hash());
|
||||
device_info[MQTT_DEVICE_MODEL] = ESPHOME_BOARD;
|
||||
#if defined(USE_ESP8266) || defined(USE_ESP32)
|
||||
device_info[MQTT_DEVICE_MANUFACTURER] = "Espressif";
|
||||
|
||||
Reference in New Issue
Block a user