|
62 | 62 | MQTT_PINGRESP = const(0xD0)
|
63 | 63 | MQTT_SUB = b"\x82"
|
64 | 64 | MQTT_UNSUB = b"\xA2"
|
65 |
| -MQTT_PUB = bytearray(b"\x30") |
66 | 65 | MQTT_DISCONNECT = b"\xe0\0"
|
67 | 66 |
|
68 | 67 | # Variable CONNECT header [MQTT 3.1.2]
|
@@ -303,8 +302,7 @@ def connect(self, clean_session=True):
|
303 | 302 | raise MMQTTException("Invalid broker address defined.", e)
|
304 | 303 |
|
305 | 304 | # Fixed Header
|
306 |
| - fixed_header = bytearray() |
307 |
| - fixed_header.append(0x10) |
| 305 | + fixed_header = bytearray([0x10]) |
308 | 306 |
|
309 | 307 | # NOTE: Variable header is
|
310 | 308 | # MQTT_HDR_CONNECT = bytearray(b"\x04MQTT\x04\x02\0\0")
|
@@ -461,13 +459,11 @@ def publish(self, topic, msg, retain=False, qos=0):
|
461 | 459 | 0 <= qos <= 1
|
462 | 460 | ), "Quality of Service Level 2 is unsupported by this library."
|
463 | 461 |
|
464 |
| - pub_hdr_fixed = bytearray() # fixed header |
465 |
| - pub_hdr_fixed.extend(MQTT_PUB) |
466 |
| - pub_hdr_fixed[0] |= retain | qos << 1 # [3.3.1.2], [3.3.1.3] |
| 462 | + # fixed header. [3.3.1.2], [3.3.1.3] |
| 463 | + pub_hdr_fixed = bytearray([0x30 | retain | qos << 1]) |
467 | 464 |
|
468 |
| - pub_hdr_var = bytearray() # variable header |
469 |
| - pub_hdr_var.append(len(topic) >> 8) # Topic length, MSB |
470 |
| - pub_hdr_var.append(len(topic) & 0xFF) # Topic length, LSB |
| 465 | + # variable header = 2-byte Topic length (big endian) |
| 466 | + pub_hdr_var = bytearray(struct.pack(">H", len(topic))) |
471 | 467 | pub_hdr_var.extend(topic.encode("utf-8")) # Topic name
|
472 | 468 |
|
473 | 469 | remaining_length = 2 + len(msg) + len(topic)
|
@@ -688,21 +684,6 @@ def reconnect(self, resub_topics=True):
|
688 | 684 | feed = subscribed_topics.pop()
|
689 | 685 | self.subscribe(feed)
|
690 | 686 |
|
691 |
| - def loop_forever(self): |
692 |
| - """Starts a blocking message loop. Use this |
693 |
| - method if you want to run a program forever. |
694 |
| - Code below a call to this method will NOT execute. |
695 |
| -
|
696 |
| - .. note:: This method is depreciated and will be removed in the |
697 |
| - next major release. Please see |
698 |
| - `examples/minimqtt_pub_sub_blocking.py <examples.html#basic-forever-loop>`_ |
699 |
| - for an example of creating a blocking loop which can handle wireless |
700 |
| - network events. |
701 |
| - """ |
702 |
| - while True: |
703 |
| - if self._sock.connected: |
704 |
| - self.loop() |
705 |
| - |
706 | 687 | def loop(self):
|
707 | 688 | """Non-blocking message loop. Use this method to
|
708 | 689 | check incoming subscription messages.
|
|
0 commit comments