Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions micropython/umqtt.simple/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ follows MQTT control operations, and maps them to class methods:
* ``ping()`` - Ping server (response is processed automatically by wait_msg()).
* ``publish()`` - Publish a message.
* ``subscribe()`` - Subscribe to a topic.
* ``unsubscribe()`` - Unsubscribe to a topic.
* ``set_callback()`` - Set callback for received subscription messages.
* ``set_last_will()`` - Set MQTT "last will" message. Should be called
*before* connect().
Expand Down
2 changes: 1 addition & 1 deletion micropython/umqtt.simple/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(description="Lightweight MQTT client for MicroPython.", version="1.6.0")
metadata(description="Lightweight MQTT client for MicroPython.", version="1.7.0")

# Originally written by Paul Sokolovsky.

Expand Down
13 changes: 13 additions & 0 deletions micropython/umqtt.simple/umqtt/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ def subscribe(self, topic, qos=0):
raise MQTTException(resp[3])
return

def unsubscribe(self, topic):
pkt = bytearray(b"\xa2\0\0\0")
self.pid += 1
struct.pack_into("!BH", pkt, 1, 2 + 2 + len(topic), self.pid)
self.sock.write(pkt)
self._send_str(topic)
while 1:
op = self.wait_msg()
if op == 0xB0:
resp = self.sock.read(3)
assert resp[1] == pkt[2] and resp[2] == pkt[3]
return

# Wait for a single incoming MQTT message and process it.
# Subscribed messages are delivered to a callback previously
# set by .set_callback() method. Other (internal) MQTT
Expand Down
Loading