From d5fdd11c1929e3d476fd8fcf754dfbd6906e1325 Mon Sep 17 00:00:00 2001 From: Bert Melis Date: Fri, 20 May 2022 16:48:36 +0200 Subject: [PATCH] fix DUP flag --- library.json | 2 +- library.properties | 2 +- src/MqttClient.cpp | 1 + src/Packets/Packet.cpp | 24 +++--------------------- src/Packets/Packet.h | 2 +- 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/library.json b/library.json index 20eb7fb..1704c36 100644 --- a/library.json +++ b/library.json @@ -14,7 +14,7 @@ "type": "git", "url": "https://github.com/bertmelis/espMqttClient.git" }, - "version": "0.0.2", + "version": "0.0.3", "frameworks": "arduino", "platforms": ["espressif8266", "espressif32"] } \ No newline at end of file diff --git a/library.properties b/library.properties index b031629..51a13a8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=espMqttClient -version=0.0.2 +version=0.0.3 author=Bert Melis maintainer=Bert Melis sentence=an MQTT client for the Arduino framework for ESP8266 / ESP32 diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 94a5667..5adf261 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -305,6 +305,7 @@ void MqttClient::_checkOutgoing() { } else { // handle with care! millis() returns unsigned 32 bit, token is void* packet->token = reinterpret_cast(millis()); + if ((packet->data(0)[0] & 0xF0) == PacketType.PUBLISH) packet->setDup(); _outbox.next(); } packet = _outbox.getCurrent(); diff --git a/src/Packets/Packet.cpp b/src/Packets/Packet.cpp index e5d6d28..ee11dec 100644 --- a/src/Packets/Packet.cpp +++ b/src/Packets/Packet.cpp @@ -43,28 +43,10 @@ size_t Packet::size() const { return _size; } -/* -Removeable is treated as "_packetId != 0" hence can be filtered out by -calling `packetId()`. -Packets without packet ID will return 0. - -bool Packet::removeable() const { - if (!_data) return true; - uint8_t packetType = _data[0] & 0xF0; - uint8_t headerFlags = _data[0] & 0x0F; - // part of session data for clients are - // - QoS 1 and 2 messages sent to server but not yet completely acked - // - QoS 2 messages received from server but not yet completely acked - if ((packetType == PacketType.PUBREC) || - (packetType == PacketType.PUBREL) || - (packetType == PacketType.PUBCOMP) || - (packetType == PacketType.PUBLISH && headerFlags & 0x06)) { // mask QoS bits - return false; - } else { - return true; - } +void Packet::setDup() { + if (!data) return; + _data[0] |= 0x08; } -*/ uint16_t Packet::packetId() const { return _packetId; diff --git a/src/Packets/Packet.h b/src/Packets/Packet.h index 84535cb..a05e1d3 100644 --- a/src/Packets/Packet.h +++ b/src/Packets/Packet.h @@ -28,7 +28,7 @@ class Packet { const uint8_t* data(size_t index) const; size_t size() const; - // bool removeable() const // functionality offered by packetId() + void setDup(); uint16_t packetId() const; void* token; // native typeless variable to store any additional data