如何测试ESP32 mDNS demo

gavinl
Posts: 24
Joined: Fri Oct 22, 2021 5:53 pm

如何测试ESP32 mDNS demo

Postby gavinl » Tue Nov 02, 2021 12:09 am

我已经加载ESP32 mDNS Demo, 我可以在Win10, ping esp32-mdns.local
如何通过网络浏览器访问设备?

这些代码是做什么用的?
//initialize service
ESP_ERROR_CHECK( mdns_service_add("ESP32-WebServer", "_http", "_tcp", 80, serviceTxtData, 3) );
//add another TXT item
ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "path", "/foobar") );
//change TXT item value
ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "u", "admin") );

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: 如何测试ESP32 mDNS demo

Postby ESP_YJM » Tue Nov 02, 2021 2:24 am

ESP32 mDNS Demo 只是 mDNS 的服务,你如果想浏览器访问,就需要 HTTP Server 服务。你可以在 HTTP Server 示例里面添加 mDNS 功能。

ESP_ERROR_CHECK( mdns_service_add("ESP32-WebServer", "_http", "_tcp", 80, serviceTxtData, 3) );
这个是告诉其他设备我支持的服务,支持 http 服务,端口 80,但是这个只是告诉其他设备,而不是自己真正支持,自己支持的话要创建 HTTP Server.

ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "path", "/foobar") );
设置自己 item 里的值,HTTP URI 资源的路径为 http://esp32-mdns.local/foobar

ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "u", "admin") );
设置自己 item 里的值

gavinl
Posts: 24
Joined: Fri Oct 22, 2021 5:53 pm

Re: 如何测试ESP32 mDNS demo

Postby gavinl » Tue Nov 02, 2021 6:23 pm

mdns_service_txt_item_set("_http", "_tcp", "path", "/foobar") 和 mdns_service_txt_item_set("_http", "_tcp", "u", "admin") 与 serviceTxtData 有什么关系吗?

Code: Select all

 //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) );
    //add another TXT item
    ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "path", "/foobar") );
    //change TXT item value
    ESP_ERROR_CHECK( mdns_service_txt_item_set("_http", "_tcp", "u", "admin") );
    
我只是复制粘贴上面的代码到https 示例代码, 我可以访问demo中的页面,但不能访问 https://esp32-mdns.local/foolbar

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: 如何测试ESP32 mDNS demo

Postby ESP_YJM » Mon Nov 15, 2021 7:10 am

https server 示例也只是访问自己本身资源,如果要访问/foolbar,需要修改

Code: Select all

static const httpd_uri_t root = {
    .uri = "/foolbar",
    .method = HTTP_GET,
    .handler = root_get_handler
};
mdns_service_txt_item_set("_http", "_tcp", "path", "/foobar") 和 mdns_service_txt_item_set("_http", "_tcp", "u", "admin") 与 serviceTxtData 有什么关系吗?->其实类似的,都是 key, value 键值对。

Who is online

Users browsing this forum: No registered users and 93 guests