limit mqtt queue to 300

This commit is contained in:
MichaelDvP
2023-09-20 12:16:36 +02:00
parent ba7ceca798
commit 9c33b5cb8b
2 changed files with 12 additions and 3 deletions

View File

@@ -594,12 +594,20 @@ bool Mqtt::queue_message(const uint8_t operation, const std::string & topic, con
}
// check free mem
#ifndef EMSESP_STANDALONE
if (ESP.getFreeHeap() < 60 * 1204) {
if (ESP.getFreeHeap() < 60 * 1204 || ESP.getMaxAllocHeap() < 40 * 1024) {
if (operation == Operation::PUBLISH) {
mqtt_message_id_++;
mqtt_publish_fails_++;
}
LOG_DEBUG("%s failed: low memory", operation == Operation::PUBLISH ? "Publish" : operation == Operation::SUBSCRIBE ? "Subscribe" : "Unsubscribe");
LOG_WARNING("%s failed: low memory", operation == Operation::PUBLISH ? "Publish" : operation == Operation::SUBSCRIBE ? "Subscribe" : "Unsubscribe");
return false; // quit
}
if (queuecount_ >= MQTT_QUEUE_MAX_SIZE) {
if (operation == Operation::PUBLISH) {
mqtt_message_id_++;
mqtt_publish_fails_++;
}
LOG_WARNING("%s failed: queue full", operation == Operation::PUBLISH ? "Publish" : operation == Operation::SUBSCRIBE ? "Subscribe" : "Unsubscribe");
return false; // quit
}
#endif

View File

@@ -56,6 +56,7 @@ class Mqtt {
enum NestedFormat : uint8_t { NESTED = 1, SINGLE };
static constexpr uint8_t MQTT_TOPIC_MAX_SIZE = 128; // fixed, not a user setting anymore
static constexpr uint16_t MQTT_QUEUE_MAX_SIZE = 300;
static void on_connect();
static void on_disconnect(espMqttClientTypes::DisconnectReason reason);