Automatically set mqtt buffer size (#637)

* Automatically set mqtt buffer size

Current versions of pubsubclient allows the buffer size to be set
dynamically: https://github.com/knolleary/pubsubclient/pull/282

We can take advantage of this to avoid having to modify one of the
dependencies and instead automatically up the buffer size when a
powerful board is detected.
This commit is contained in:
Jens Balvig authored and GitHub committed 2020-06-18 05:36:40 -05:00
1 parent 2bb8feffed
commit 1e599415fc
7 files changed
+17 -34

No files matched your search

+6 -4
View File
@@ -97,11 +97,13 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield
//MQTT Parameters definition
//#define mqtt_server_name "www.mqtt_broker.com" // instead of defining the server by its IP you can define it by its name, uncomment this line and set the correct MQTT server host name
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
# define parameters_size 20
# define mqtt_topic_max_size 100
# define parameters_size 20
# define mqtt_topic_max_size 100
# define mqtt_max_packet_size 1024
#else
# define parameters_size 15
# define mqtt_topic_max_size 50
# define parameters_size 15
# define mqtt_topic_max_size 50
# define mqtt_max_packet_size 128
#endif
char mqtt_user[parameters_size] = "your_username"; // not compulsory only if your broker needs authentication
char mqtt_pass[parameters_size] = "your_password"; // not compulsory only if your broker needs authentication
+2 -5
View File
@@ -401,6 +401,7 @@ void connectMQTT() {
char topic[mqtt_topic_max_size];
strcpy(topic, mqtt_topic);
strcat(topic, will_Topic);
client.setBufferSize(mqtt_max_packet_size);
if (client.connect(gateway_name, mqtt_user, mqtt_pass, topic, will_QoS, will_Retain, will_Message)) {
#if defined(ZboardM5STICKC) || defined(ZboardM5STACK)
if (low_power_mode < 2)
@@ -604,11 +605,7 @@ void setup() {
#ifdef ZsensorDHT
setupDHT();
#endif
Log.trace(F("MQTT_MAX_PACKET_SIZE: %d" CR), MQTT_MAX_PACKET_SIZE);
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
if (MQTT_MAX_PACKET_SIZE == 128)
Log.error(F("WRONG PUBSUBCLIENT LIBRARY USED PLEASE INSTALL THE ONE FROM RELEASE PAGE" CR));
#endif
Log.trace(F("mqtt_max_packet_size: %d" CR), mqtt_max_packet_size);
Log.notice(F("Setup OpenMQTTGateway end" CR));
}