Remove last traces of external mqtt abstraction
Also subscribed to commander and changed name of vote request message.
This commit is contained in:
@@ -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[""]
|
||||
|
||||
Reference in New Issue
Block a user