Skip to content

Subscribe to multiple topics using a single request #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions MQTT.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ def pubcomp(self, messageId):
self.transport.write(str(header))
self.transport.write(str(varHeader))

def subscribe(self, topic, requestedQoS=0, messageId=None):
def subscribe(self, topics, messageId=None):
"""
Only supports QoS = 0 subscribes
Only supports one subscription per message
Subscribe to the given topics. Topics is expected to be a list
of (topic, qos) tuples.
"""
header = bytearray()
varHeader = bytearray()
Expand All @@ -408,8 +408,9 @@ def subscribe(self, topic, requestedQoS=0, messageId=None):
else:
varHeader.extend(self._encodeValue(messageId))

payload.extend(self._encodeString(topic))
payload.append(requestedQoS)
for topic, qos in topics:
payload.extend(self._encodeString(topic))
payload.append(qos)

header.extend(self._encodeLength(len(varHeader) + len(payload)))

Expand Down