mqtt DNS lookup failed err=202 res=0x0

xcmonline
Posts: 9
Joined: Tue Dec 14, 2021 1:42 pm

mqtt DNS lookup failed err=202 res=0x0

Postby xcmonline » Sun Dec 19, 2021 2:17 pm

Code: Select all

nvs_flash_init();
    tcpip_adapter_init();


    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    wifi_config_t sta_config = {
        .sta = {
            .ssid = CONFIG_ESP_WIFI_SSID,
            .password = CONFIG_ESP_WIFI_PASSWORD,
            .bssid_set = false
        }
    };
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
    ESP_ERROR_CHECK( esp_wifi_connect() );

    //MQTT
    const esp_mqtt_client_config_t mqtt_cfg = {
    	.client_id="1234567",
        .host = "mqtt://192.168.3.6",//服务器IP地址 默认端口 1883
	.port = 1883
    };
    esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
    esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
    esp_mqtt_client_start(client);

在运行时显示:
E (5807) TRANS_TCP: DNS lookup failed err=202 res=0x0
E (5807) MQTT_CLIENT: Error transport connect

但wifi看了路由器是连接成功的。

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

Re: mqtt DNS lookup failed err=202 res=0x0

Postby ESP_YJM » Mon Dec 20, 2021 7:08 am

mqtt_cfg 里把 host 改成 uri

xcmonline
Posts: 9
Joined: Tue Dec 14, 2021 1:42 pm

Re: mqtt DNS lookup failed err=202 res=0x0

Postby xcmonline » Mon Dec 20, 2021 1:33 pm

ESP_YJM wrote:
Mon Dec 20, 2021 7:08 am
mqtt_cfg 里把 host 改成 uri
修改了后报:
E (5807) TRANS_TCP: [sock=54] connect() error: Host is unreachable
E (5807) MQTT_CLIENT: Error transport connect

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

Re: mqtt DNS lookup failed err=202 res=0x0

Postby ESP_YJM » Tue Dec 21, 2021 8:19 am

确认下这个地址是否可达?

xcmonline
Posts: 9
Joined: Tue Dec 14, 2021 1:42 pm

Re: mqtt DNS lookup failed err=202 res=0x0

Postby xcmonline » Tue Dec 21, 2021 1:30 pm

都是在同一局域网内,同一台路由器,ip与端口使用其他mqtt软件正常连接。

xcmonline
Posts: 9
Joined: Tue Dec 14, 2021 1:42 pm

Re: mqtt DNS lookup failed err=202 res=0x0

Postby xcmonline » Tue Dec 21, 2021 2:48 pm

已解决

Goodboy~
Posts: 1
Joined: Wed Sep 21, 2022 12:53 pm

Re: mqtt DNS lookup failed err=202 res=0x0

Postby Goodboy~ » Wed Sep 21, 2022 12:56 pm

怎么解决的呀 说一下呀

mw1472005
Posts: 1
Joined: Thu Apr 20, 2023 4:02 am

Re: mqtt DNS lookup failed err=202 res=0x0

Postby mw1472005 » Thu Apr 20, 2023 4:07 am

简单点说,这个错误是因为你输入了错误的地址或端口导致的,所以解决办法就是先确认一下自己输入的地址是否正确就可以了

Who is online

Users browsing this forum: No registered users and 34 guests