1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-07-27 15:01:49 +03:00

fixes processUntil

This commit is contained in:
brentru
2022-10-28 12:27:33 -04:00
parent 7413e92e77
commit 0ba089d1e8
2 changed files with 33 additions and 3 deletions

View File

@ -226,6 +226,9 @@ uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer,
uint8_t waitforpackettype, uint8_t waitforpackettype,
uint16_t timeout) { uint16_t timeout) {
uint16_t len; uint16_t len;
DEBUG_PRINTLN("call: processPacketsUntil()");
DEBUG_PRINT("Looking for packetType: ");
DEBUG_PRINTLN(waitforpackettype);
while (true) { while (true) {
len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); len = readFullPacket(buffer, MAXBUFFERSIZE, timeout);
@ -239,7 +242,31 @@ uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer,
return len; return len;
} else { } else {
if (packetType == MQTT_CTRL_PUBLISH) { if (packetType == MQTT_CTRL_PUBLISH) {
handleSubscriptionPacket(len);
Adafruit_MQTT_Subscribe *sub = handleSubscriptionPacket(len);
if (sub) {
DEBUG_PRINTLN("processPacketsUntil got subscription!");
if (sub->callback_uint32t != NULL) {
// huh lets do the callback in integer mode
uint32_t data = 0;
data = atoi((char *)sub->lastread);
sub->callback_uint32t(data);
} else if (sub->callback_double != NULL) {
// huh lets do the callback in doublefloat mode
double data = 0;
data = atof((char *)sub->lastread);
sub->callback_double(data);
} else if (sub->callback_buffer != NULL) {
// huh lets do the callback in buffer mode
DEBUG_PRINTLN("processPacketsUntil called the callback_buffer!");
sub->callback_buffer((char *)sub->lastread, sub->datalen);
} else if (sub->callback_io != NULL) {
// huh lets do the callback in io mode
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread,
sub->datalen);
}
}
} else { } else {
ERROR_PRINTLN(F("Dropped a packet")); ERROR_PRINTLN(F("Dropped a packet"));
} }
@ -477,8 +504,10 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
uint32_t elapsed = 0, endtime, starttime = millis(); uint32_t elapsed = 0, endtime, starttime = millis();
while (elapsed < (uint32_t)timeout) { while (elapsed < (uint32_t)timeout) {
DEBUG_PRINTLN("L480: readSubscription() called by processPackets()");
Adafruit_MQTT_Subscribe *sub = readSubscription(timeout - elapsed); Adafruit_MQTT_Subscribe *sub = readSubscription(timeout - elapsed);
if (sub) { if (sub) {
DEBUG_PRINTLN("processPackets got subscription!");
if (sub->callback_uint32t != NULL) { if (sub->callback_uint32t != NULL) {
// huh lets do the callback in integer mode // huh lets do the callback in integer mode
uint32_t data = 0; uint32_t data = 0;
@ -491,6 +520,7 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
sub->callback_double(data); sub->callback_double(data);
} else if (sub->callback_buffer != NULL) { } else if (sub->callback_buffer != NULL) {
// huh lets do the callback in buffer mode // huh lets do the callback in buffer mode
DEBUG_PRINTLN("processPackets callback_buffer!");
sub->callback_buffer((char *)sub->lastread, sub->datalen); sub->callback_buffer((char *)sub->lastread, sub->datalen);
} else if (sub->callback_io != NULL) { } else if (sub->callback_io != NULL) {
// huh lets do the callback in io mode // huh lets do the callback in io mode

View File

@ -34,7 +34,7 @@
#define ADAFRUIT_MQTT_VERSION_PATCH 0 #define ADAFRUIT_MQTT_VERSION_PATCH 0
// Uncomment/comment to turn on/off debug output messages. // Uncomment/comment to turn on/off debug output messages.
//#define MQTT_DEBUG #define MQTT_DEBUG
// Uncomment/comment to turn on/off error output messages. // Uncomment/comment to turn on/off error output messages.
#define MQTT_ERROR #define MQTT_ERROR
@ -107,7 +107,7 @@
// Largest full packet we're able to send. // Largest full packet we're able to send.
// Need to be able to store at least ~90 chars for a connect packet with full // Need to be able to store at least ~90 chars for a connect packet with full
// 23 char client ID. // 23 char client ID.
#define MAXBUFFERSIZE (150) #define MAXBUFFERSIZE (512)
#define MQTT_CONN_USERNAMEFLAG 0x80 #define MQTT_CONN_USERNAMEFLAG 0x80
#define MQTT_CONN_PASSWORDFLAG 0x40 #define MQTT_CONN_PASSWORDFLAG 0x40