Arduino Ethernet Bonjour / ZeroConf Networking Library

Over the last few months I've been updating the Arduino EthernetBonjour library still available online at http://gkaindl.com/software/arduino-ethernet. The original library was written for Arduino 0017 and required separate libraries for DNS and DHCP. With Arduino 1.x these are not required anymore as they are part of the Arduino Ethernet library.

The main reason for the overhaul is that the original library made 50+ calls directly to the W5100 Ethernet chip and as such was very hardware dependent. I had already upgraded it to work with Arduino 1.x and also to work with the W5200 Ethernet Chip found for example on the WIZ820io Ethernet Module.

The new library is more or less hardware independent. Bonjour and its underlying mechanisms mDNS and DNS-SD use UDP as its base protocol. As such the overhauled library only works with calls to the read/write methods from the EthernetUDP. This should greatly help to adapt it to other hardware and I am hoping for support from the community. The CC3000 from Texas Instruments would be a good candidate.

The changes to the Bonjour library also necessitated the addition of a routine to the EthernetUDP library in order to allow sending UDP multicast messages, required to implement mDNS and DNS-SD. This has been very similarly discussed on the Arduino forum over a year ago UDP Multicast Sending from Arduino via Ethernet Shield - Networking, Protocols, and Devices - Arduino Forum.

EthernetUDP.h needs these lines aded in the sensible places:

virtual uint8_t beginMulti(IPAddress, uint16_t);	// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use Sending UDP packets
.
.
.
friend class EthernetBonjourClass;

EthernetUDP.cpp need this added routine:

/* Start EthernetUDP socket, listening at local port PORT */
uint8_t EthernetUDP::beginMulti(IPAddress ip, uint16_t port) {

  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    uint8_t s = W5100.readSnSR(i);
    if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
      _sock = i;
      break;
    }
  }

  if (_sock == MAX_SOCK_NUM)
    return 0;

  byte mac[] = {  0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 };

  mac[3] = ip[1] & 0x7F;
  mac[4] = ip[2];
  mac[5] = ip[3];

//  byte mac[] = { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb };

  W5100.writeSnDIPR(_sock, rawIPAddress(ip));
  W5100.writeSnDPORT(_sock, port);
  W5100.writeSnDHAR(_sock,mac);

  _remaining = 0;

  socket(_sock, SnMR::UDP, port, SnMR::MULTI);

  return 1;
}

As noted in the documentation on the original web site, the library compiles to a relatively large chunk of code and is aimed at bigger boards with more flash and ram memory. I don't own an Arduino Mega and in recent projects only have used Paul Stoffregen's Teensy boards Teensy USB Development Board .
The Examples provided in the library compile and work out of the box with a Teensy++2 <-> WIZ812MJ and with a Teensy 3 <-> WIZ820io.

The new library is available here:

Thanks a lot! I tried this library on an Arduino Mega2560 with Arduino 1.5.5 and it worked flawlessly (after editing EthernetUdp.h/.cpp).

Good to hear! Thanks for the feedback!

Dear all experts,

I'm a newbie to use this bonjour-ethernet library. So far, I have followed this instruction to add the beginMulti and tried on Arduino Uno.

But it ... doesn't show anything in my serial monitor... Not sure why.. please advise me.

Thank you very very much.

edit edit edit.... I got the program to compile, but ethernet doesn't work after making the changes to the ethernetudp.h and .cpp files.

edit again...I redid the ethernet files since the shield is just totally non-functional now. I had forgotten I was using ethernet2 files and renamed them ethernet to avoid situations like this. So, here's where I am now...

Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/thatdamnrainbow/Documents/Arduino/libraries/Ethernet2/src/EthernetUdp2.cpp: In member function 'virtual uint8_t EthernetUDP::beginMulti(IPAddress, uint16_t)':
/Users/thatdamnrainbow/Documents/Arduino/libraries/Ethernet2/src/EthernetUdp2.cpp:227:16: error: 'W5100' was not declared in this scope
uint8_t s = W5100.readSnSR(i);
^
/Users/thatdamnrainbow/Documents/Arduino/libraries/Ethernet2/src/EthernetUdp2.cpp:245:2: error: 'W5100' was not declared in this scope
W5100.writeSnDIPR(_sock, rawIPAddress(ip));
^
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

edit again: it seems these changes do not work with the ethernet2 library, which we W5500 users need.