Skip to content

Commit f063eb0

Browse files
committed
update codes, upgrade MQTT support codes.
1 parent a850c66 commit f063eb0

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

src/modules/mqtt/Adafruit_MQTT.cpp

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -536,45 +536,47 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
536536
}
537537

538538
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
539-
uint16_t i, topiclen, datalen;
539+
uint16_t i, topiclen, datalen;
540540

541-
// Check if data is available to read.
542-
uint16_t len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
543-
if (!len)
544-
return NULL; // No data available, just quit.
545-
DEBUG_PRINT("Packet len: "); DEBUG_PRINTLN(len);
546-
DEBUG_PRINTBUFFER(buffer, len);
547-
548-
// Parse out length of packet.
549-
if(len <= 129)
550-
topiclen = buffer[3];
551-
else
552-
topiclen = buffer[4];
553-
DEBUG_PRINT(F("Looking for subscription len ")); DEBUG_PRINTLN(topiclen);
554-
555-
// Find subscription associated with this packet.
556-
for (i=0; i<MAXSUBSCRIPTIONS; i++) {
557-
if (subscriptions[i]) {
558-
// Skip this subscription if its name length isn't the same as the
559-
// received topic name.
560-
if (strlen(subscriptions[i]->topic) != topiclen)
561-
continue;
562-
// Stop if the subscription topic matches the received topic. Be careful
563-
// to make comparison case insensitive.
564-
if(len <= 129) {
565-
if (strncasecmp((char*)buffer+4, subscriptions[i]->topic, topiclen) == 0) {
566-
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
567-
break;
568-
}
569-
}
570-
else {
571-
if (strncasecmp((char*)buffer+5, subscriptions[i]->topic, topiclen) == 0) {
572-
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
573-
break;
541+
// Check if data is available to read.
542+
uint16_t len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
543+
if (!len)
544+
return NULL; // No data available, just quit.
545+
DEBUG_PRINT("Packet len: "); DEBUG_PRINTLN(len);
546+
DEBUG_PRINTBUFFER(buffer, len);
547+
548+
// Parse out length of packet.
549+
if (len < 3) return NULL;
550+
551+
if (len <= 129)
552+
topiclen = buffer[3];
553+
else
554+
topiclen = buffer[4];
555+
DEBUG_PRINT(F("Looking for subscription len ")); DEBUG_PRINTLN(topiclen);
556+
557+
// Find subscription associated with this packet.
558+
for (i=0; i<MAXSUBSCRIPTIONS; i++) {
559+
if (subscriptions[i]) {
560+
// Skip this subscription if its name length isn't the same as the
561+
// received topic name.
562+
if (strlen(subscriptions[i]->topic) != topiclen)
563+
continue;
564+
// Stop if the subscription topic matches the received topic. Be careful
565+
// to make comparison case insensitive.
566+
if(len <= 129) {
567+
if (strncasecmp((char*)buffer+4, subscriptions[i]->topic, topiclen) == 0) {
568+
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
569+
break;
570+
}
571+
}
572+
else {
573+
if (strncasecmp((char*)buffer+5, subscriptions[i]->topic, topiclen) == 0) {
574+
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
575+
break;
576+
}
577+
}
574578
}
575-
}
576579
}
577-
}
578580
if (i==MAXSUBSCRIPTIONS) {
579581
DEBUG_PRINTLN(F("Not found sub #"));
580582

0 commit comments

Comments
 (0)