How to ping a local URL ???

Baldhead
Posts: 467
Joined: Sun Mar 31, 2019 5:16 am

How to ping a local URL ???

Postby Baldhead » Wed Jul 05, 2023 12:52 am

Hi,

I am trying to ping a local url address, but not worked.

I am trying like the code below in a AP WITHOUT internet connection.

With " #define MY_PING_URL "www.espressif.com" " worked, in a AP with internet connection obviously.

In windows cmd, "ping myfota.local", worked, image in annex.

Pinging local address by ip address worked too.
Some "local dns" problem maybe.

esp-idf Monitor:

Code: Select all

I (11098) MY_PING_APP: Unknown host: [ http://myfota.local ]
I (11098) MY_PING_APP: ret = 202

Code: Select all

// I tried with this two defines
//#define MY_PING_URL "myfota.local"
#define MY_PING_URL "http://myfota.local"

esp_err_t initialize_ping()
{
    // convert URL to IP address
    ip_addr_t target_addr;
    struct addrinfo hint;
    struct addrinfo *res = NULL;
    
    memset(&hint, 0, sizeof(hint));
    memset(&target_addr, 0, sizeof(target_addr));
    
    int ret = getaddrinfo(MY_PING_URL, NULL, &hint, &res);
    if( ret != 0 )
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Unknown host: [ %s ]" ), MY_PING_URL );
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "ret = %d\n" ), ret );
        return ESP_ERR_NOT_FOUND;
    }

    if( res->ai_family == AF_INET )  // ipv4
    {
        struct in_addr addr4 = ( (struct sockaddr_in *) (res->ai_addr) )->sin_addr;
	inet_addr_to_ip4addr( ip_2_ip4( &target_addr ), &addr4 );

        //target_addr.type = IPADDR_TYPE_V4;

        ESP_LOGI( MY_PING_TAG, LOG_USER1( "IPv4 = %s" ), ip4addr_ntoa( &(target_addr.u_addr.ip4) ) );
    }
    else if( res->ai_family == AF_INET6 )  // ipv6
    {
        struct in6_addr addr6 = ( (struct sockaddr_in6 *) (res->ai_addr) )->sin6_addr;
	inet6_addr_to_ip6addr( ip_2_ip6( &target_addr ), &addr6 );

        //target_addr.type = IPADDR_TYPE_V6;

        ESP_LOGI( MY_PING_TAG, LOG_USER1( "IPv6 = %s" ), ip6addr_ntoa( &(target_addr.u_addr.ip6) ) );
    }
    else  // unknown
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Unknown family = %d" ), res->ai_family );        
    }

    freeaddrinfo(res);



    esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
    ping_config.target_addr = target_addr;  // target IP address
    ping_config.count = ESP_PING_COUNT_INFINITE;    // ping in infinite mode, esp_ping_stop can stop it
    ping_config.timeout_ms = 5000;

    // set callback functions
    esp_ping_callbacks_t cbs;
    cbs.on_ping_success = test_on_ping_success;
    cbs.on_ping_timeout = test_on_ping_timeout;
    cbs.on_ping_end = test_on_ping_end;
    cbs.cb_args = NULL;  // arguments that will feed to all callback functions, can be NULL
    
    esp_ping_handle_t ping;
    
    esp_err_t e = esp_ping_new_session(&ping_config, &cbs, &ping);
    if( e != ESP_OK )
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Nao foi possivel criar a sessao ping !!!\nError = %s\n" ), esp_err_to_name( e ) );
        return e;
    }
        
    e = esp_ping_start(ping);
    if( e != ESP_OK )
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Nao foi possivel iniciar o ping !!!\nError = %s\n" ), esp_err_to_name( e ) );
        return e;
    }

    ESP_LOGI( MY_PING_TAG, LOG_USER1( "My Ping Start" ) );
    return ESP_OK;
}
Notes:
* esp-idf v5.1
* esp32-s3
* I am trying to connect esp32-S3 to Apache Server running on windows 11 to do a FOTA. I am using XAMPP.
* https://github.com/espressif/esp-idf/issues/11792
* https://github.com/espressif/esp-idf/issues/11814

Thank's.
Attachments
ping_local_url.jpg
ping_local_url.jpg (59.97 KiB) Viewed 3565 times
Last edited by Baldhead on Fri Jul 07, 2023 6:11 pm, edited 1 time in total.

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: How to ping a local URL ???

Postby ESP_Sprite » Wed Jul 05, 2023 2:14 am

That's a MDNS address. You may need to enable/start MDNS support on the ESP32 for that to work.

Baldhead
Posts: 467
Joined: Sun Mar 31, 2019 5:16 am

Re: How to ping a local URL ???

Postby Baldhead » Wed Jul 05, 2023 3:25 am

ESP_Sprite wrote:
Wed Jul 05, 2023 2:14 am
That's a MDNS address. You may need to enable/start MDNS support on the ESP32 for that to work.
Hi @ESP_Sprite

I have mdns enabled on esp32, running together with my wss server.

I use the mdns for my android app encounter wss server.

Now i want that esp32 encounter the web server running on my desktop windows 11.

I thought maybe netbios or some local dns would run on windows.

I'm using dd wrt on my AP too. Maybe some way to configure dd wrt to operate as a local dns server, but I don't know how.

Baldhead
Posts: 467
Joined: Sun Mar 31, 2019 5:16 am

Re: How to ping a local URL ???

Postby Baldhead » Wed Jul 05, 2023 8:53 pm

Hi,

I did some tests on my AP( DD-WRT installed ) that is running DHCP server and has dnsmasq enabled.

If i remove " address=/http://myfota.local/192.168.1.201 " from DD-WRT "dns table", the chrome doesn't find "www.myfota.local" and ping from a windows command prompt, ping www.myfota.local doesn't find too, but if i put "address=/http://myfota.local/192.168.1.201 " in DD-WRT "dns table", both chrome and command prompt ping worked.

ESP32-S3 ping doesn't find the host:

Code: Select all

#define MY_PING_URL "www.myfota.local"

esp_err_t initialize_ping()
{
    // convert URL to IP address
    ip_addr_t target_addr;
    struct addrinfo hint;
    struct addrinfo *res = NULL;
    
    memset(&hint, 0, sizeof(hint));
    memset(&target_addr, 0, sizeof(target_addr));
    
    int ret = getaddrinfo(MY_PING_URL, NULL, &hint, &res);
    if( ret != 0 )
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Unknown host: [ %s ]" ), MY_PING_URL );
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "ret = %d\n" ), ret );
        return ESP_ERR_NOT_FOUND;
    }

    if( res->ai_family == AF_INET )  // ipv4
    {
        struct in_addr addr4 = ( (struct sockaddr_in *) (res->ai_addr) )->sin_addr;
        inet_addr_to_ip4addr( ip_2_ip4( &target_addr ), &addr4 );

        //target_addr.type = IPADDR_TYPE_V4;

        ESP_LOGI( MY_PING_TAG, LOG_USER1( "IPv4 = %s" ), ip4addr_ntoa( &(target_addr.u_addr.ip4) ) );
    }
    else if( res->ai_family == AF_INET6 )  // ipv6
    {
        struct in6_addr addr6 = ( (struct sockaddr_in6 *) (res->ai_addr) )->sin6_addr;
	inet6_addr_to_ip6addr( ip_2_ip6( &target_addr ), &addr6 );

        //target_addr.type = IPADDR_TYPE_V6;

        ESP_LOGI( MY_PING_TAG, LOG_USER1( "IPv6 = %s" ), ip6addr_ntoa( &(target_addr.u_addr.ip6) ) );
    }
    else  // unknown family
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Unknown family = %d" ), res->ai_family );        
    }

    freeaddrinfo(res);



    esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
    ping_config.target_addr = target_addr;  // target IP address
    ping_config.count = ESP_PING_COUNT_INFINITE;    // ping in infinite mode, esp_ping_stop can stop it
    ping_config.timeout_ms = 5000;

    // set callback functions
    esp_ping_callbacks_t cbs;
    cbs.on_ping_success = test_on_ping_success;
    cbs.on_ping_timeout = test_on_ping_timeout;
    cbs.on_ping_end = test_on_ping_end;
    cbs.cb_args = NULL;  // arguments that will feed to all callback functions, can be NULL
    
    esp_ping_handle_t ping;
    
    esp_err_t e = esp_ping_new_session(&ping_config, &cbs, &ping);
    if( e != ESP_OK )
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Nao foi possivel criar a sessao ping !!!\nError = %s\n" ), esp_err_to_name( e ) );
        return e;
    }
        
    e = esp_ping_start(ping);
    if( e != ESP_OK )
    {
        ESP_LOGI( MY_PING_TAG, LOG_USER1( "Nao foi possivel iniciar o ping !!!\nError = %s\n" ), esp_err_to_name( e ) );
        return e;
    }

    ESP_LOGI( MY_PING_TAG, LOG_USER1( "My Ping Start" ) );
    return ESP_OK;
}

Any suggestions on how to configure lwip "dns client" to work this way ?


Notes:
* Windows 11
* Image in annex: Dnsmasq_Infrastructure
Attachments
Dnsmasq_Infrastructure.jpg
Dnsmasq_Infrastructure.jpg (48.12 KiB) Viewed 3405 times

Baldhead
Posts: 467
Joined: Sun Mar 31, 2019 5:16 am

Re: How to ping a local URL ???

Postby Baldhead » Thu Jul 06, 2023 2:45 pm

Some suggestion in how to configure lwip ?

Baldhead
Posts: 467
Joined: Sun Mar 31, 2019 5:16 am

Re: How to ping a local URL ???

Postby Baldhead » Thu Jul 06, 2023 8:36 pm

I changed "address=/http://myfota.local/192.168.1.201" to "address=/http://myfota.com/192.168.1.201" from DD-WRT "dns table" and worked.

It seems that the lwip lib automatically changes the protocol for resolving the name, based on the TLD (top level domain).

TLD = .local use protocol Mdns
TLD = .com use protocol Dns

As my AP( with DD WRT ) and my apache server were not running/sending the mdns packet to the network, the name was not resolved by lwip in esp32-s3.
When i put .com in the TLD the lwip lib used the dns protocol and my AP( with DD WRT ) responded with the dns packet and esp32-s3 find the ip and send ping correctly.

Is this normal functioning of lwip's dns/mdns ?
Is there any rfc that says to use Mdns for .local address and DNS for internet address ?

Edit:
This way worked too.
#define MY_PING_URL "www.myfota.work"
"address=/http://myfota.work/192.168.1.201" from DD-WRT "dns table"

Who is online

Users browsing this forum: No registered users and 107 guests