1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-15 00:03:51 +01:00
This commit is contained in:
J. Nick Koston
2025-10-07 16:34:51 -05:00
parent 87a1040285
commit 2e1d5662ea
2 changed files with 5 additions and 2 deletions

View File

@@ -11,6 +11,8 @@
#define MDNS_STATIC_CONST_CHAR(name, value) static const char name[] PROGMEM = value #define MDNS_STATIC_CONST_CHAR(name, value) static const char name[] PROGMEM = value
#define MDNS_STR(name) (reinterpret_cast<const MDNSString *>(name)) #define MDNS_STR(name) (reinterpret_cast<const MDNSString *>(name))
// Helper to convert PROGMEM string to std::string for TemplatableValue // Helper to convert PROGMEM string to std::string for TemplatableValue
// Only define this function if we have services that will use it
#if defined(USE_API) || defined(USE_PROMETHEUS) || defined(USE_WEBSERVER) || defined(USE_MDNS_EXTRA_SERVICES)
static std::string mdns_str_value(PGM_P str) { static std::string mdns_str_value(PGM_P str) {
char buf[64]; char buf[64];
strncpy_P(buf, str, sizeof(buf) - 1); strncpy_P(buf, str, sizeof(buf) - 1);
@@ -18,6 +20,7 @@ static std::string mdns_str_value(PGM_P str) {
return std::string(buf); return std::string(buf);
} }
#define MDNS_STR_VALUE(name) mdns_str_value(name) #define MDNS_STR_VALUE(name) mdns_str_value(name)
#endif
#else #else
// On non-ESP8266 platforms, use regular const char* // On non-ESP8266 platforms, use regular const char*
#define MDNS_STATIC_CONST_CHAR(name, value) static constexpr const char name[] = value #define MDNS_STATIC_CONST_CHAR(name, value) static constexpr const char name[] = value

View File

@@ -22,11 +22,11 @@ void MDNSComponent::setup() {
// expects the underscore to be there, the ESP8266 implementation always adds // expects the underscore to be there, the ESP8266 implementation always adds
// the underscore itself. // the underscore itself.
auto *proto = MDNS_STR_ARG(service.proto); auto *proto = MDNS_STR_ARG(service.proto);
while (*proto == '_') { while (pgm_read_byte(proto) == '_') {
proto++; proto++;
} }
auto *service_type = MDNS_STR_ARG(service.service_type); auto *service_type = MDNS_STR_ARG(service.service_type);
while (*service_type == '_') { while (pgm_read_byte(service_type) == '_') {
service_type++; service_type++;
} }
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value(); uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();