Skip to content

Commit

Permalink
Update MQTT subscribe command by @0xMattijs Xinyuan-LilyGO/LilyGO-T-A…
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Dec 18, 2024
1 parent 3841a52 commit cf8af0e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/TinyGsmMqttA76xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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');
Expand Down

0 comments on commit cf8af0e

Please sign in to comment.