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();