-->
Page 1 of 1

Using WiFi.hostByName() on LAN to get Server IP address

PostPosted: Sat Dec 02, 2017 9:56 am
by bdollerup
I'm trying to not use static ip addresses for my MQTT server by using the hostByName.

When I use the command to get the ip address of an external (nttp) server, the command returns the ip address of the server just fine, but when I use the same command to get an ip address of a host on my LAN, it fails to get the ip address.

Here my code:

const char* mqttServerName ="servername";
IPAddress mqttServerIP;

WiFi.hostByName(mqttServerName, mqttServerIP)

What did I do wrong?

Thanks
bdollerup

Re: Using WiFi.hostByName() on LAN to get Server IP address

PostPosted: Sat Dec 02, 2017 6:42 pm
by QuickFix
Do you have a DNS or Bonjour running inside your LAN? :idea:

Re: Using WiFi.hostByName() on LAN to get Server IP address

PostPosted: Sat Dec 02, 2017 6:57 pm
by rudy
External names are resolved by external DNS servers. What is inside your private network is not available to external servers so you need to add a mechanism in your network for that to work.

For Mac OSX support is built in through Bonjour already.
For Linux, install Avahi.
For Windows, install Bonjour.

Re: Using WiFi.hostByName() on LAN to get Server IP address

PostPosted: Sat Dec 02, 2017 7:54 pm
by rudy
https://github.com/esp8266/Arduino/issues/3087

It seems that hostByName does not make use of mDNS.