diff --git a/src/TinyGsmMqttA76xx.h b/src/TinyGsmMqttA76xx.h index 758c49f9..4f5b1458 100644 --- a/src/TinyGsmMqttA76xx.h +++ b/src/TinyGsmMqttA76xx.h @@ -270,12 +270,14 @@ class TinyGsmMqttA76xx return true; } - bool mqtt_subscribe(uint8_t clientIndex, const char *topic, uint8_t qos = 0) + bool mqtt_subscribe(uint8_t clientIndex, const char *topic, uint8_t qos = 0, uint8_t dup = 0) { if (clientIndex > muxCount) { return false; } - thisModem().sendAT("+CMQTTSUBTOPIC=", clientIndex, ',', strlen(topic), ',', qos); + // Subscribe a message to server + // +CMQTTSUB: (0-1),(1-1024),(0-2),(0-1) + thisModem().sendAT("+CMQTTSUB=", clientIndex, ',', strlen(topic), ',', qos, ',', dup); if (thisModem().waitResponse(10000UL, ">") != 1) { return false; } @@ -286,12 +288,6 @@ class TinyGsmMqttA76xx if (thisModem().waitResponse(10000UL) != 1) { return false; } - // Subscribe a message to server - // +CMQTTSUB: (0-1),(1-1024),(0-2),(0-1) - thisModem().sendAT("+CMQTTSUB=", clientIndex); - if (thisModem().waitResponse(10000UL) != 1) { - return false; - } thisModem().waitResponse("+CMQTTSUB: "); int id = thisModem().streamGetIntBefore(','); int status = thisModem().streamGetIntBefore('\n');