@@ -536,45 +536,47 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
536
536
}
537
537
538
538
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription (int16_t timeout) {
539
- uint16_t i, topiclen, datalen;
539
+ uint16_t i, topiclen, datalen;
540
540
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
+ }
574
578
}
575
- }
576
579
}
577
- }
578
580
if (i==MAXSUBSCRIPTIONS) {
579
581
DEBUG_PRINTLN (F (" Not found sub #" ));
580
582
0 commit comments