In order to simply deploy of new Lambent devices, I decided to bake in a zeroconf (avahi) announce so that future clients could find all available instances. This worked great for the prototype kivy application being built in parallel and multiple instances could be controlled from a single interface.
Notes on my implementation
Because I was uncertain of how the interfaces on the host machine were configured. I bound the zeroconf announce to every available interface except virtual and the loopback. This ensured I would have working announced on every interface, be it wifi or ethernet.
def announce(self, discovery_name, port=8680):
self.zeroconf = Zeroconf()
self.zconfigs = []
for i in netifaces.interfaces():
if i.startswith("lo"):
# remove loopback from announce
continue
if i.startswith("veth"):
# remove docker interface from announce
continue
addrs = netifaces.ifaddresses(i)
if addrs.keys() == [17]:
continue
for a in addrs[netifaces.AF_INET]:
info_desc = {'path': '/progs_grp/', 'name': discovery_name, "port":port}
config = ServiceInfo("_aether._tcp.local.",
"%s_%s_%s_lambent._aether._tcp.local." % (socket.gethostname(),i, port),
socket.inet_aton(a['addr']), port, 0, 0,
info_desc)
try:
self.zeroconf.register_service(config)
self.zconfigs.append(config)
except:
print("Service %s failed to register" % config)