equal
deleted
inserted
replaced
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 import socket, threading |
25 import socket, threading |
26 from util import Zeroconf |
26 from util import Zeroconf |
27 |
27 |
|
28 service_type = '_PYRO._tcp.local.' |
|
29 |
28 class ServicePublisher(): |
30 class ServicePublisher(): |
29 def __init__(self): |
31 def __init__(self): |
30 # type: fully qualified service type name |
32 # type: fully qualified service type name |
31 self.service_type = '_PYRO._tcp.local.' |
|
32 # properties: dictionary of properties (or a string holding the bytes for the text field) |
|
33 self.serviceproperties = {'description':'Beremiz remote PLC'} |
33 self.serviceproperties = {'description':'Beremiz remote PLC'} |
34 |
34 |
35 self.name = None |
35 self.name = None |
36 self.ip_32b = None |
36 self.ip_32b = None |
37 self.port = None |
37 self.port = None |
46 self.retrytimer = threading.Timer(2,self.RegisterService,[name, ip, port]) |
46 self.retrytimer = threading.Timer(2,self.RegisterService,[name, ip, port]) |
47 self.retrytimer.start() |
47 self.retrytimer.start() |
48 |
48 |
49 def _RegisterService(self, name, ip, port): |
49 def _RegisterService(self, name, ip, port): |
50 # name: fully qualified service name |
50 # name: fully qualified service name |
51 self.service_name = 'Beremiz_%s.%s'%(name,self.service_type) |
51 self.service_name = 'Beremiz_%s.%s'%(name,service_type) |
52 self.name = name |
52 self.name = name |
53 self.port = port |
53 self.port = port |
54 |
54 |
55 self.server = Zeroconf.Zeroconf(ip) |
55 self.server = Zeroconf.Zeroconf(ip) |
56 print "MDNS brodcasting on :"+ip |
56 print "MDNS brodcasting on :"+ip |
59 ip = self.gethostaddr() |
59 ip = self.gethostaddr() |
60 print "MDNS brodcasted service address :"+ip |
60 print "MDNS brodcasted service address :"+ip |
61 self.ip_32b = socket.inet_aton(ip) |
61 self.ip_32b = socket.inet_aton(ip) |
62 |
62 |
63 self.server.registerService( |
63 self.server.registerService( |
64 Zeroconf.ServiceInfo(self.service_type, |
64 Zeroconf.ServiceInfo(service_type, |
65 self.service_name, |
65 self.service_name, |
66 self.ip_32b, |
66 self.ip_32b, |
67 self.port, |
67 self.port, |
68 properties = self.serviceproperties)) |
68 properties = self.serviceproperties)) |
69 self.retrytimer=None |
69 self.retrytimer=None |
71 def UnRegisterService(self): |
71 def UnRegisterService(self): |
72 if self.retrytimer is not None: |
72 if self.retrytimer is not None: |
73 self.retrytimer.cancel() |
73 self.retrytimer.cancel() |
74 |
74 |
75 self.server.unregisterService( |
75 self.server.unregisterService( |
76 Zeroconf.ServiceInfo(self.service_type, |
76 Zeroconf.ServiceInfo(service_type, |
77 self.service_name, |
77 self.service_name, |
78 self.ip_32b, |
78 self.ip_32b, |
79 self.port, |
79 self.port, |
80 properties = self.serviceproperties)) |
80 properties = self.serviceproperties)) |
81 self.server.close() |
81 self.server.close() |