runtime/ServicePublisher.py
changeset 2492 7dd551ac2fa0
parent 2477 4866c01e7428
child 3750 f62625418bff
equal deleted inserted replaced
2491:362039519454 2492:7dd551ac2fa0
    29 import zeroconf
    29 import zeroconf
    30 
    30 
    31 
    31 
    32 service_type = '_Beremiz._tcp.local.'
    32 service_type = '_Beremiz._tcp.local.'
    33 
    33 
       
    34 
    34 class ServicePublisher(object):
    35 class ServicePublisher(object):
    35     def __init__(self, protocol):
    36     def __init__(self, protocol):
    36         # type: fully qualified service type name
    37         # type: fully qualified service type name
    37         self.serviceproperties = {
    38         self.serviceproperties = {
    38             'description': 'Beremiz remote PLC',
    39             'description': 'Beremiz remote PLC',
    59         self.name = name
    60         self.name = name
    60         self.port = port
    61         self.port = port
    61 
    62 
    62         if ip == "0.0.0.0":
    63         if ip == "0.0.0.0":
    63             print("MDNS brodcasted on all interfaces")
    64             print("MDNS brodcasted on all interfaces")
    64             interfaces=zeroconf.InterfaceChoice.All
    65             interfaces = zeroconf.InterfaceChoice.All
    65             ip = self.gethostaddr()
    66             ip = self.gethostaddr()
    66         else:
    67         else:
    67             interfaces=[ip]
    68             interfaces = [ip]
    68 
    69 
    69         self.server = zeroconf.Zeroconf(interfaces=interfaces)
    70         self.server = zeroconf.Zeroconf(interfaces=interfaces)
    70         
    71 
    71         print("MDNS brodcasted service address :" + ip)
    72         print("MDNS brodcasted service address :" + ip)
    72         self.ip_32b = socket.inet_aton(ip)
    73         self.ip_32b = socket.inet_aton(ip)
    73 
    74 
    74         self.server.register_service(
    75         self.server.register_service(
    75             zeroconf.ServiceInfo(service_type,
    76             zeroconf.ServiceInfo(service_type,