diff --git a/DecisionSystem/CentralisedDecision/commander.py b/DecisionSystem/CentralisedDecision/commander.py index 2265063..f97f0b4 100644 --- a/DecisionSystem/CentralisedDecision/commander.py +++ b/DecisionSystem/CentralisedDecision/commander.py @@ -20,11 +20,13 @@ class Commander: self.client = mqtt.Client() self.client.connect('172.16.13.128') + self.client.subscribe("swarm1/commander") # Commander needs a will message too, for the decentralised version, so the # voters know to pick a new commander. + # If using apache zookeeper this won't be needed. def make_decision(self): - # Could change this to be a strategy, for different implementations of making + # Should change this to be a strategy, for different implementations of making # a decision on the votes. votes = self._votes dif_votes = {} @@ -46,26 +48,28 @@ class Commander: return max_vote def get_votes(): - message = {"type": "voteRequest"} + message = {"type": "reqVote"} message_packed = umsgpack.packb(message) # Publish a message that votes are needed. - ms.client.publish("swarm1/voters", message_packed, qos) + self.client.publish("swarm1/voters", message_packed, qos) time.sleep(self.timeout) self.make_decision() - def add_subscription(self, topic, callback=None, qos=0): - ms.client.subscribe(topic) + # Shouldn't be needed anymore. + # def add_subscription(self, topic, callback=None, qos=0): + # self.client.subscribe(topic) - if callback is not None: - ms.client.message_callback_add(topic, callback) + # if callback is not None: + # selfclient.message_callback_add(topic, callback) def on_message(self, client, userdata, message): messageDict = umsgpack.unpackb() + if "type" in messageDict.keys: if messageDict["type"] == "connect": # Voter just connected/reconnnected. - + pass elif messageDict["type"] == "vote": # Voter is sending in their vote. if messageDict[""]