Multicast DNS

One enhancement to the candy bowl monitor server is to use multicast DNS to simplify connecting to the server. With MDNS the server can be assigned a local address like 'candybowl.local' which is used instead of the IP address to connect to the server. This means you don't need to know the IP address of the server (which can change each time the server connects to your network) and instead only need to know the fixed local address/name of the server.

To use MDNS with the candy bowl monitor, first download and install the CC3000 MDNS Arduino library. A direct download link is below:
Unzip the library into a folder in your Arduino sketchbook/libraries directory. See the guide on Arduino libraries if you aren't sure exactly what to do. Make sure to restart the Arduino IDE after installing the library.

Next you will want to make sure you have MDNS (or ZeroConf/Bonjour) support available to your operating system.
  • For Mac OSX support should be provided automatically by Bonjour.
  • For Linux, make sure Avahi is installed. For recent versions of Ubuntu this should already be installed.
  • For Windows, make sure Bonjour for windows is installed.
Now load the 'Candybowl_Server_MDNS' sketch that was downloaded earlier. Configure this sketch in the same way as the first one, compile it, and load it on your Arduino.

Once the serial monitor displays the 'Listening for connections...' message, telnet to the 'candybowl.local' address. For example using a terminal session type:

telnet candybowl.local

After a short period of time you should see the telnet server find the IP address of the server and connect to it. You can send the same question mark command as the first server example to check the candy bowl status.

If you want to change the MDNS address of the server, just modify the call to the mdns.begin() function line in the setup() function of the sketch. By default the call looks like:

mdns.begin("candybowl", cc3000, 3600)

This means the server will listen for the 'candybowl.local' address (by convention all MDNS addresses end in '.local'). Try changing the value of the first parameter, recompiling, and uploading the sketch to have the server respond to a new address.

Also for reference the last parameter to the call specifies the time to live for the DNS record in seconds. In this case the sketch is setting a TTL of 3600 seconds, or one hour. This means your computer will cache the mapping of 'candybowl.local' to the server IP address for up to an hour. If you frequently disconnect and reconnect the server so the IP address changes, you might want to drop this down to a lower value like a few minutes. If you don't specify this third parameter, a default TTL of 1 hour will be used.

Feel free to use this simple MDNS library in your own server projects!

Continue on wrap up and look at future work you can do with this project.
This guide was first published on Oct 29, 2013. It was last updated on Oct 29, 2013. This page (Multicast DNS) was last updated on Mar 19, 2020.