mDNS not working for ftp - one specific use case

I have two esp8266, one is sensing oil levels (oilsensor.local), the other delivered a webpage showing levels (oiltank.local).

On both devices I can use filezilla to upload/download files using the hostname instead of their IP addresses.

I can upload files from oilsensor.local to my Synology NAS using the hostname (diskstation.local).

I CANNOT upload files from oilsensor.local to oiltank.local using the hostname (oiltank.local), but I can upload files from oilsensor.local to oiltank.local using its IP address??

The relevant bit of code at the start of my ftp upload function in oilsensor.local:

WiFiClient ftpclient; //control
ftpclient.connect(remoteclient.host,21);
//remoteclient.host = "diskstation.local" = okay
//remoteclient.host = "oiltank.local" = fail to connect
//remoteclient.host = "192.168.0.231" = okay, this is the IP for oiltank.local

I don't understand why my code works for the NAS, oiltank.local is okay with filezilla, but it fails to connect with oiltank.local in my code.

I did find a snippet of code on the web which I implemented:

void testmdns(){
  int nrOfServices = MDNS.queryService("http", "tcp");
  if (nrOfServices == 0) {
    Serial.println("No services were found.");
    } 
  else {
    Serial.print("Number of services found: ");
    Serial.println(nrOfServices);
    for (int i = 0; i < nrOfServices; i=i+1) {
         Serial.print("Hostname: "); Serial.println(MDNS.hostname(i));
         Serial.print("IP address: "); Serial.println(MDNS.IP(i));
         Serial.print("Port: "); Serial.println(MDNS.port(i));
        }
    }
}

It works, finds oiltank.local:

Hostname: oiltank.local
IP address: 192.168.0.231
Port: 80

I can use this to resolve the hostname to an IP address, but a bit clunky, is there a function of the form MDNS.get_IP_address("hostname"), that will return the IP address, documentation is a bit sparse.

But the main question is why doesn't it work in the first place.
The loop in oiltank.local is running:

  if (WiFi.status() != WL_CONNECTED) wifiConnect(); 
  ftpSrv.handleFTP(); 
  server.handleClient();  
  MDNS.update(); 

Most probably because the WiFiClient supports only DNS names and not mDNS. I guess that your NAS has some code to provide the hostname by DNS and not only by mDNS and that's why it works there but it won't work for the ESPs.

If you need that functionality, use the MDNS object to get the IP address (as you do above) and then use that address to connect to the FTP server.

Despite it's name mDNS isn't a DNS service, it supplies just a similar service but a DNS client doesn't get that information. Each client that wants to support it has to specifically implement the mDNS protocol in addition to the DNS protocol.

Thanks for the reply.

If you need that functionality, use the MDNS object to get the IP address (as you do above) and then use that address to connect to the FTP server.

That is exactly what I've done.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.