+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
======
::
- 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:
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
::
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
''''''''''''''''''
VERSION_MAJOR=0
VERSION_MINOR=9
-VERSION_REVISION=1
+VERSION_REVISION=100
VERSION_NUMBER=(VERSION_MAJOR*1000000+VERSION_MINOR*1000+VERSION_REVISION)
MQTTv31 = 3
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
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)
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:
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
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
# 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
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)