Created
April 24, 2018 06:40
-
-
Save forslund/ba45fe61d4007fdfd7893977603e049d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zeroconf import ServiceBrowser, Zeroconf | |
class MycroftListener(object): | |
def __init__(self): | |
self.devices = {} | |
def remove_service(self, zeroconf, type, name): | |
print("Service %s removed" % (name,)) | |
self.devices.pop(name) | |
def add_service(self, zeroconf, dev_type, name): | |
info = zeroconf.get_service_info(dev_type, name) | |
self.devices[name] = info | |
ip = [i for i in info.address] | |
port = info.port | |
addr = '{}.{}.{}.{}'.format(ip[0], ip[1], ip[2], ip[3], port) | |
print('{} at {}:{}'.format(name, addr, port)) | |
zeroconf = Zeroconf() | |
listener = MycroftListener() | |
browser = ServiceBrowser(zeroconf, "_mycroft._tcp.local.", listener) | |
try: | |
input("Press enter to exit...\n\n") | |
finally: | |
zeroconf.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" standalone='no'?><!--*-nxml-*--> | |
<!DOCTYPE service-group SYSTEM "avahi-service.dtd"> | |
<service-group> | |
<name replace-wildcards="yes">Mycroft</name> | |
<service> | |
<type>_mycroft._tcp</type> | |
<port>8181</port> | |
</service> | |
</service-group> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment