HTTP Client call fails using hostname but works when using IPaddress

(This problem may be related to Previous HTTP Client Issue)

I have a local 3rd party device I'm trying to access using the HTTP Client library 0.0.5
I can successfully access it using its ip address, however when using its assigned hostname it fails (HttpClient> Connection failed.) When using a web browser both cases work fine
(i.e. lvroom.local/aircon/get_control_info).

Am I using an old version of the HTTP Client library?
Anyone have any suggestions?

getRequest("10.0.6.30"); //This works
getRequest("lvroom.local"); //This DOES NOT work

HttpClient http;
http_request_t request;
http_response_t response;
http_header_t headers[] = {
    { "Content-type", "application/x-www-form-urlencoded" },
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};
String getRequest(String sHostname)
{
    // Request path and body can be set at runtime or at setup.
    request.hostname = sHostname;
    request.port = 80;
    request.path = "/aircon/get_control_info";

    http.get(request, response, headers);

    Serial.print("Response status: ");
    Serial.println(response.status);
    Serial.print("HTTP Response Body: ");
    Serial.println(response.body);

    return response.body;
}

The DNS resolver in Device OS does not support mDNS (multicast DNS) so it cannot resolve any .local domains.

There is a MDNS library but I haven't used it for many years and I'm not positive if it works on the Argon, but it would be worth a try. Use the library to resolve the .local hostname to an IP address, then use the IP address with httpclient.

1 Like

Thanks Rick - will do.

FYI I just tried the below. www.google.com worked. lvroom.local did not.
T.

ip = WiFi.resolve("lvroom.local");
Serial.println(ip);
ip = WiFi.resolve("www.google.com");
Serial.println(ip);

Correct. The DNS resolver in Device OS I think will use the DNS server specified by your router, and possibly also 8.8.8.8, but in any case the standard top-level domains work. It's just .local that uses mDNS over multicast UDP, not regular DNS over regular UDP.

Looked at the mDNS library. Not really a clear path for retrieving an ip address from a .local hostname (as far as I can see).

BTW the reason I want to use .local instead of ip (hard coded) is because the ISP I use has reset my modem/router in the past for their convenience during area-wide trouble shooting and upgrades. This has caused all my local ips to be newly assigned (as well as clearing all static settings, port forwarding, etc.) Nice people.

It hasn't happened in a long time, so I guess I can use the currently assigned ip address. Just thought I could "simply" use the .local name. Programming gods said "no".

Sorry, I thought the mdns library also included the client but it apparently does not.

I would try to port the ArduinoMDNS library. It includes mdns-sd (service discovery) which is what you need. These tips may be helpful.

1 Like

Thanks Rick. As always your help is greatly appreciated. I might climb this hill at later date. For now I’ll use the known IP address.