Files
deckenlampe/main/mymdns.cpp
T

55 lines
1.5 KiB
C++
Raw Normal View History

2021-07-15 13:17:07 +02:00
#include "mymdns.h"
// esp-idf includes
#include <mdns.h>
#include <esp_log.h>
// local includes
#include "myconfig.h"
namespace deckenlampe {
namespace {
constexpr const char * const TAG = "MDNS";
} // namespace
void init_mdns()
{
2021-07-15 16:38:04 +02:00
if (!config::enable_mdns.value())
2021-07-15 14:12:01 +02:00
return;
2021-07-15 13:17:07 +02:00
{
const auto result = mdns_init();
ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), TAG, "mdns_init(): %s", esp_err_to_name(result));
if (result != ESP_OK)
return;
}
{
2021-07-15 16:38:04 +02:00
const auto result = mdns_hostname_set(config::hostname.value().c_str());
2021-07-15 13:17:07 +02:00
ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), TAG, "mdns_hostname_set(): %s", esp_err_to_name(result));
//if (result != ESP_OK)
// return result;
}
{
2021-07-15 16:38:04 +02:00
const auto result = mdns_instance_name_set(config::hostname.value().c_str());
2021-07-15 13:17:07 +02:00
ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), TAG, "mdns_instance_name_set(): %s", esp_err_to_name(result));
//if (result != ESP_OK)
// return result;
}
2021-07-15 16:38:04 +02:00
if (config::enable_webserver.value())
2021-07-15 13:17:07 +02:00
{
const auto result = mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);
ESP_LOG_LEVEL_LOCAL((result == ESP_OK ? ESP_LOG_INFO : ESP_LOG_ERROR), TAG, "mdns_service_add(): %s", esp_err_to_name(result));
//if (result != ESP_OK)
// return result;
}
}
void update_mdns()
{
2021-07-15 16:38:04 +02:00
if (!config::enable_mdns.value())
2021-07-15 14:12:01 +02:00
return;
2021-07-15 13:17:07 +02:00
}
} // namespace deckenlampe