mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
limit mqtt queue to 300
This commit is contained in:
12
src/mqtt.cpp
12
src/mqtt.cpp
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user