shorter suback timeout

This commit is contained in:
ladyada 2016-07-08 15:21:47 -04:00
parent bb240928e8
commit 9ed79466b2
3 changed files with 10 additions and 4 deletions

View File

@ -31,6 +31,7 @@ static char *dtostrf (double val, signed char width, unsigned char prec, char *s
#endif #endif
void printBuffer(uint8_t *buffer, uint16_t len) { void printBuffer(uint8_t *buffer, uint16_t len) {
DEBUG_PRINTER.print('\t');
for (uint16_t i=0; i<len; i++) { for (uint16_t i=0; i<len; i++) {
if (isprint(buffer[i])) if (isprint(buffer[i]))
DEBUG_PRINTER.write(buffer[i]); DEBUG_PRINTER.write(buffer[i]);
@ -41,7 +42,9 @@ void printBuffer(uint8_t *buffer, uint16_t len) {
DEBUG_PRINTER.print("0"); DEBUG_PRINTER.print("0");
DEBUG_PRINTER.print(buffer[i],HEX); DEBUG_PRINTER.print(buffer[i],HEX);
DEBUG_PRINTER.print("], "); DEBUG_PRINTER.print("], ");
if (i % 8 == 7) DEBUG_PRINTER.println(); if (i % 8 == 7) {
DEBUG_PRINTER.print("\n\t");
}
} }
DEBUG_PRINTER.println(); DEBUG_PRINTER.println();
} }
@ -216,7 +219,7 @@ int8_t Adafruit_MQTT::connect() {
// TODO: The Server is permitted to start sending PUBLISH packets matching the // TODO: The Server is permitted to start sending PUBLISH packets matching the
// Subscription before the Server sends the SUBACK Packet. (will really need to use callbacks - ada) // Subscription before the Server sends the SUBACK Packet. (will really need to use callbacks - ada)
len = processPacketsUntil(buffer, MQTT_CTRL_SUBACK, CONNECT_TIMEOUT_MS); len = processPacketsUntil(buffer, MQTT_CTRL_SUBACK, SUBACK_TIMEOUT_MS);
if ((len != 5) || (buffer[0] != (MQTT_CTRL_SUBACK << 4))) { if ((len != 5) || (buffer[0] != (MQTT_CTRL_SUBACK << 4))) {
continue; // retry! continue; // retry!
} }

View File

@ -30,7 +30,9 @@
#endif #endif
// 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.
#define MQTT_ERROR
// Set where debug messages will be printed. // Set where debug messages will be printed.
#define DEBUG_PRINTER Serial #define DEBUG_PRINTER Serial
@ -71,6 +73,7 @@
#define CONNECT_TIMEOUT_MS 6000 #define CONNECT_TIMEOUT_MS 6000
#define PUBLISH_TIMEOUT_MS 500 #define PUBLISH_TIMEOUT_MS 500
#define PING_TIMEOUT_MS 500 #define PING_TIMEOUT_MS 500
#define SUBACK_TIMEOUT_MS 500
// Adjust as necessary, in seconds. Default to 5 minutes. // Adjust as necessary, in seconds. Default to 5 minutes.
#define MQTT_CONN_KEEPALIVE 300 #define MQTT_CONN_KEEPALIVE 300

View File

@ -82,7 +82,7 @@ bool Adafruit_MQTT_Client::sendPacket(uint8_t *buffer, uint16_t len) {
// send 250 bytes at most at a time, can adjust this later based on Client // send 250 bytes at most at a time, can adjust this later based on Client
uint16_t sendlen = min(len, 250); uint16_t sendlen = min(len, 250);
Serial.print("Sending: "); Serial.println(sendlen); //Serial.print("Sending: "); Serial.println(sendlen);
ret = client->write(buffer, sendlen); ret = client->write(buffer, sendlen);
DEBUG_PRINT(F("Client sendPacket returned: ")); DEBUG_PRINTLN(ret); DEBUG_PRINT(F("Client sendPacket returned: ")); DEBUG_PRINTLN(ret);
len -= ret; len -= ret;