60 lines
1.9 KiB
C
60 lines
1.9 KiB
C
/*! Copyright 2023 Bogdan Pilyugin
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* \file mDNS.c
|
|
* \version 1.0
|
|
* \date 2023-01-29
|
|
* \author Bogdan Pilyugin
|
|
* \brief
|
|
* \details
|
|
* \copyright Apache License, Version 2.0
|
|
*/
|
|
|
|
#include "mdns.h"
|
|
#include "webguiapp.h"
|
|
#include "esp_log.h"
|
|
#include "netdb.h"
|
|
|
|
static const char *TAG = "mDNS";
|
|
|
|
#define EXAMPLE_MDNS_INSTANCE "msdn_esp32_inst"
|
|
|
|
void mDNSServiceStart(void)
|
|
{
|
|
const char hostname[] = "test_host_name";
|
|
//initialize mDNS
|
|
ESP_ERROR_CHECK(mdns_init());
|
|
//set mDNS hostname (required if you want to advertise services)
|
|
ESP_ERROR_CHECK(mdns_hostname_set(hostname));
|
|
ESP_LOGI(TAG, "mdns hostname set to: [%s]", hostname);
|
|
//set default mDNS instance name
|
|
ESP_ERROR_CHECK(mdns_instance_name_set("esp_32"));
|
|
|
|
//structure with TXT records
|
|
mdns_txt_item_t serviceTxtData[3] = {
|
|
{ "board", "esp32" },
|
|
{ "u", "user" },
|
|
{ "p", "password" }
|
|
};
|
|
|
|
//initialize service
|
|
ESP_ERROR_CHECK(mdns_service_add("ESP32-WebServer", "_http", "_tcp", 80, serviceTxtData, 3));
|
|
ESP_ERROR_CHECK(mdns_service_add("ESP32-WebServer1", "_http", "_tcp", 80, NULL, 0));
|
|
|
|
ESP_ERROR_CHECK(mdns_service_txt_item_set("_http", "_tcp", "path", "/foobar"));
|
|
|
|
ESP_ERROR_CHECK(mdns_service_txt_item_set_with_explicit_value_len("_http", "_tcp", "u", "admin", strlen("admin")));
|
|
}
|
|
|