diff --git a/Kconfig b/Kconfig index 2c274ca..9eb6c0b 100644 --- a/Kconfig +++ b/Kconfig @@ -152,6 +152,13 @@ menu "ESP-MQTT Configurations" bool "Core 1" endchoice + config MQTT_OUTBOX_DATA_ON_EXTERNAL_MEMORY + bool "Use external memory for outbox data" + default n + depends on MQTT_USE_CUSTOM_CONFIG + help + Set to true to use external memory for outbox data. + config MQTT_CUSTOM_OUTBOX bool "Enable custom outbox implementation" default n diff --git a/lib/include/mqtt_config.h b/lib/include/mqtt_config.h index 6238ee1..409fb3c 100644 --- a/lib/include/mqtt_config.h +++ b/lib/include/mqtt_config.h @@ -19,10 +19,10 @@ #define MQTT_RECON_DEFAULT_MS (10*1000) #ifdef CONFIG_MQTT_POLL_READ_TIMEOUT_MS -#define MQTT_POLL_READ_TIMEOUT_MS CONFIG_MQTT_POLL_READ_TIMEOUT_MS +#define MQTT_POLL_READ_TIMEOUT_MS CONFIG_MQTT_POLL_READ_TIMEOUT_MS #else #define MQTT_POLL_READ_TIMEOUT_MS (1000) -#endif +#endif #define MQTT_MSG_ID_INCREMENTAL CONFIG_MQTT_MSG_ID_INCREMENTAL @@ -107,5 +107,11 @@ #define MQTT_EVENT_QUEUE_SIZE 1 #endif +#ifdef CONFIG_MQTT_OUTBOX_DATA_ON_EXTERNAL_MEMORY +#define MQTT_OUTBOX_MEMORY MALLOC_CAP_SPIRAM +#else +#define MQTT_OUTBOX_MEMORY MALLOC_CAP_DEFAULT +#endif + #define OUTBOX_MAX_SIZE (4*1024) #endif diff --git a/lib/mqtt_outbox.c b/lib/mqtt_outbox.c index 5680e8a..f60a471 100644 --- a/lib/mqtt_outbox.c +++ b/lib/mqtt_outbox.c @@ -1,7 +1,9 @@ #include "mqtt_outbox.h" #include #include +#include "mqtt_config.h" #include "sys/queue.h" +#include "esp_heap_caps.h" #include "esp_log.h" #ifndef CONFIG_MQTT_CUSTOM_OUTBOX @@ -31,7 +33,7 @@ outbox_handle_t outbox_init(void) outbox_item_handle_t outbox_enqueue(outbox_handle_t outbox, outbox_message_handle_t message, outbox_tick_t tick) { - outbox_item_handle_t item = calloc(1, sizeof(outbox_item_t)); + outbox_item_handle_t item = heap_caps_calloc(1, sizeof(outbox_item_t), MQTT_OUTBOX_MEMORY); ESP_MEM_CHECK(TAG, item, return NULL); item->msg_id = message->msg_id; item->msg_type = message->msg_type;