Skip to content

Commit 0ba089d

Browse files
committed
fixes processUntil
1 parent 7413e92 commit 0ba089d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Adafruit_MQTT.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer,
226226
uint8_t waitforpackettype,
227227
uint16_t timeout) {
228228
uint16_t len;
229+
DEBUG_PRINTLN("call: processPacketsUntil()");
230+
DEBUG_PRINT("Looking for packetType: ");
231+
DEBUG_PRINTLN(waitforpackettype);
229232

230233
while (true) {
231234
len = readFullPacket(buffer, MAXBUFFERSIZE, timeout);
@@ -239,7 +242,31 @@ uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer,
239242
return len;
240243
} else {
241244
if (packetType == MQTT_CTRL_PUBLISH) {
242-
handleSubscriptionPacket(len);
245+
246+
Adafruit_MQTT_Subscribe *sub = handleSubscriptionPacket(len);
247+
if (sub) {
248+
DEBUG_PRINTLN("processPacketsUntil got subscription!");
249+
if (sub->callback_uint32t != NULL) {
250+
// huh lets do the callback in integer mode
251+
uint32_t data = 0;
252+
data = atoi((char *)sub->lastread);
253+
sub->callback_uint32t(data);
254+
} else if (sub->callback_double != NULL) {
255+
// huh lets do the callback in doublefloat mode
256+
double data = 0;
257+
data = atof((char *)sub->lastread);
258+
sub->callback_double(data);
259+
} else if (sub->callback_buffer != NULL) {
260+
// huh lets do the callback in buffer mode
261+
DEBUG_PRINTLN("processPacketsUntil called the callback_buffer!");
262+
sub->callback_buffer((char *)sub->lastread, sub->datalen);
263+
} else if (sub->callback_io != NULL) {
264+
// huh lets do the callback in io mode
265+
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread,
266+
sub->datalen);
267+
}
268+
}
269+
243270
} else {
244271
ERROR_PRINTLN(F("Dropped a packet"));
245272
}
@@ -477,8 +504,10 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
477504
uint32_t elapsed = 0, endtime, starttime = millis();
478505

479506
while (elapsed < (uint32_t)timeout) {
507+
DEBUG_PRINTLN("L480: readSubscription() called by processPackets()");
480508
Adafruit_MQTT_Subscribe *sub = readSubscription(timeout - elapsed);
481509
if (sub) {
510+
DEBUG_PRINTLN("processPackets got subscription!");
482511
if (sub->callback_uint32t != NULL) {
483512
// huh lets do the callback in integer mode
484513
uint32_t data = 0;
@@ -491,6 +520,7 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
491520
sub->callback_double(data);
492521
} else if (sub->callback_buffer != NULL) {
493522
// huh lets do the callback in buffer mode
523+
DEBUG_PRINTLN("processPackets callback_buffer!");
494524
sub->callback_buffer((char *)sub->lastread, sub->datalen);
495525
} else if (sub->callback_io != NULL) {
496526
// huh lets do the callback in io mode

Adafruit_MQTT.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define ADAFRUIT_MQTT_VERSION_PATCH 0
3535

3636
// Uncomment/comment to turn on/off debug output messages.
37-
//#define MQTT_DEBUG
37+
#define MQTT_DEBUG
3838
// Uncomment/comment to turn on/off error output messages.
3939
#define MQTT_ERROR
4040

@@ -107,7 +107,7 @@
107107
// Largest full packet we're able to send.
108108
// Need to be able to store at least ~90 chars for a connect packet with full
109109
// 23 char client ID.
110-
#define MAXBUFFERSIZE (150)
110+
#define MAXBUFFERSIZE (512)
111111

112112
#define MQTT_CONN_USERNAMEFLAG 0x80
113113
#define MQTT_CONN_PASSWORDFLAG 0x40

0 commit comments

Comments
 (0)