]> git.michaelhowe.org Git - packages/p/paho-mqtt.git/commitdiff
[434143] Default protocol is now MQTT v3.1.1.
authorRoger A. Light <roger@atchoo.org>
Mon, 12 May 2014 21:35:23 +0000 (22:35 +0100)
committerRoger A. Light <roger@atchoo.org>
Mon, 12 May 2014 21:35:23 +0000 (22:35 +0100)
Connecting from both client.py and publish.py will use MQTT v3.1.1 by
default.

Client will reconnect using MQTT v3.1 if a v3.1.1 connection fails due to
the incorrect protocol version number.

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=434143
Change-Id: I34c4288535b99c8a4f05d92f9e3c99d1fa07b5c1

ChangeLog.txt
README.rst
src/paho/mqtt/client.py
src/paho/mqtt/publish.py
test/paho_test.py

index 380bcf190d5812fdaba908386531359f8219a26d..5558be2dfd16bfa4548f976ba011c23a4bc3ac57 100644 (file)
@@ -1,3 +1,10 @@
+v1.0
+====
+
+- Default protocol is now MQTT v3.1.1.
+- Client will reconnect using MQTT v3.1 if a v3.1.1 connection fails due to
+  the incorrect protocol version number.
+
 v0.9.1
 ======
 
index 75b57832025e6c7c3c0b4a0426038a99a7c5ff08..ddc5149e856280b95b3fe13e70b906bf23a3813b 100644 (file)
@@ -127,7 +127,7 @@ Client()
 
 ::
 
-    Client(client_id="", clean_session=True, userdata=None, protocol=MQTTv31)
+    Client(client_id="", clean_session=True, userdata=None, protocol=MQTTv311)
 
 The ``Client()`` constructor takes the following arguments:
 
@@ -815,7 +815,7 @@ Publish a single message to a broker, then disconnect cleanly.
 
     single(topic, payload=None, qos=0, retain=False, hostname="localhost",
         port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None,
-        protocol=mqtt.MQTTv31)
+        protocol=mqtt.MQTTv311)
            
 
 Function arguments
@@ -892,7 +892,7 @@ Publish multiple messages to a broker, then disconnect cleanly.
 ::
 
     multiple(msgs, hostname="localhost", port=1883, client_id="", keepalive=60,
-        will=None, auth=None, tls=None, protocol=mqtt.MQTTv31)
+        will=None, auth=None, tls=None, protocol=mqtt.MQTTv311)
 
 Function arguments
 ''''''''''''''''''
index 0e421d5f893e181ce801728db4849ad7de408f88..1f754835fa002ed262980b107744438c492c3b13 100755 (executable)
@@ -47,7 +47,7 @@ else:
 
 VERSION_MAJOR=0
 VERSION_MINOR=9
-VERSION_REVISION=1
+VERSION_REVISION=100
 VERSION_NUMBER=(VERSION_MAJOR*1000000+VERSION_MINOR*1000+VERSION_REVISION)
 
 MQTTv31 = 3
@@ -375,7 +375,7 @@ class Client(object):
       MQTT_LOG_ERR, and MQTT_LOG_DEBUG. The message itself is in buf.
 
     """
-    def __init__(self, client_id="", clean_session=True, userdata=None, protocol=MQTTv31):
+    def __init__(self, client_id="", clean_session=True, userdata=None, protocol=MQTTv311):
         """client_id is the unique client id string used when connecting to the
         broker. If client_id is zero length or None, then one will be randomly
         generated. In this case, clean_session must be True. If this is not the
@@ -1713,8 +1713,8 @@ class Client(object):
         command = CONNECT
         packet = bytearray()
         packet.extend(struct.pack("!B", command))
-        self._pack_remaining_length(packet, remaining_length)
 
+        self._pack_remaining_length(packet, remaining_length)
         packet.extend(struct.pack("!H"+str(len(protocol))+"sBBH", len(protocol), protocol, proto_ver, connect_flags, keepalive))
 
         self._pack_str16(packet, self._client_id)
@@ -1905,6 +1905,12 @@ class Client(object):
             return MQTT_ERR_PROTOCOL
 
         (resvd, result) = struct.unpack("!BB", self._in_packet['packet'])
+        if result == CONNACK_REFUSED_PROTOCOL_VERSION and self._protocol == MQTTv311:
+            self._easy_log(MQTT_LOG_DEBUG, "Received CONNACK ("+str(resvd)+", "+str(result)+"), attempting downgrade to MQTT v3.1.")
+            # Downgrade to MQTT v3.1
+            self._protocol = MQTTv31
+            return self.reconnect()
+
         self._easy_log(MQTT_LOG_DEBUG, "Received CONNACK ("+str(resvd)+", "+str(result)+")")
         self._callback_mutex.acquire()
         if self.on_connect:
index c1d1a26c48d096ab1a48c3a444196fa008c26f8f..89aae28351c1d75a4c591200a1a3f573a2103829 100644 (file)
@@ -63,7 +63,7 @@ def _on_publish(c, userdata, mid):
 
 
 def multiple(msgs, hostname="localhost", port=1883, client_id="", keepalive=60,
-             will=None, auth=None, tls=None, protocol=mqtt.MQTTv31):
+             will=None, auth=None, tls=None, protocol=mqtt.MQTTv311):
     """Publish multiple messages to a broker, then disconnect cleanly.
 
     This function creates an MQTT client, connects to a broker and publishes a
@@ -173,7 +173,7 @@ def multiple(msgs, hostname="localhost", port=1883, client_id="", keepalive=60,
 
 def single(topic, payload=None, qos=0, retain=False, hostname="localhost",
            port=1883, client_id="", keepalive=60, will=None, auth=None,
-           tls=None, protocol=mqtt.MQTTv31):
+           tls=None, protocol=mqtt.MQTTv311):
     """Publish a single message to a broker, then disconnect cleanly.
 
     This function creates an MQTT client, connects to a broker and publishes a
index 111e524889f7969b6eb5d5b964a4400b1fc48a16..a16c5d4a310053fab76716e75925f20bdb88a2b9 100644 (file)
@@ -201,11 +201,11 @@ def to_string(packet):
         # Reserved
         return "0xF0"
 
-def gen_connect(client_id, clean_session=True, keepalive=60, username=None, password=None, will_topic=None, will_qos=0, will_retain=False, will_payload="", proto_ver=3):
+def gen_connect(client_id, clean_session=True, keepalive=60, username=None, password=None, will_topic=None, will_qos=0, will_retain=False, will_payload="", proto_name="MQTT", proto_ver=4):
     if client_id == None:
         remaining_length = 12
     else:
-        remaining_length = 12 + 2+len(client_id)
+        remaining_length = 2+len(proto_name) + 1+1+2 + 2+len(client_id)
     connect_flags = 0
     if clean_session:
         connect_flags = connect_flags | 0x02
@@ -225,7 +225,7 @@ def gen_connect(client_id, clean_session=True, keepalive=60, username=None, pass
 
     rl = pack_remaining_length(remaining_length)
     packet = struct.pack("!B"+str(len(rl))+"s", 0x10, rl)
-    packet = packet + struct.pack("!H6sBBH", len("MQIsdp"), "MQIsdp", proto_ver, connect_flags, keepalive)
+    packet = packet + struct.pack("!H"+str(len(proto_name))+"sBBH", len(proto_name), proto_name, proto_ver, connect_flags, keepalive)
     if client_id != None:
         packet = packet + struct.pack("!H"+str(len(client_id))+"s", len(client_id), client_id)