diff --git a/Kconfig b/Kconfig index 858db35..45c4cfc 100644 --- a/Kconfig +++ b/Kconfig @@ -20,11 +20,6 @@ config ESP_MQTT_TASK_PRIORITY depends on ESP_MQTT_ENABLED default 5 -config ESP_MQTT_TASK_CORE - int "MQTT background process task core" - depends on ESP_MQTT_ENABLED - default 1 - config ESP_MQTT_EVENT_QUEUE_SIZE int "MQTT event queue size" depends on ESP_MQTT_ENABLED diff --git a/esp_mqtt.c b/esp_mqtt.c index 87258dc..ee10c38 100644 --- a/esp_mqtt.c +++ b/esp_mqtt.c @@ -70,6 +70,7 @@ static esp_lwmqtt_timer_t esp_mqtt_timer1, esp_mqtt_timer2; static void *esp_mqtt_write_buffer; static void *esp_mqtt_read_buffer; +static int esp_mqtt_core; static QueueHandle_t esp_mqtt_event_queue = NULL; @@ -80,12 +81,15 @@ typedef struct { } esp_mqtt_event_t; void esp_mqtt_init(esp_mqtt_status_callback_t scb, esp_mqtt_message_callback_t mcb, size_t buffer_size, - int command_timeout) { + int command_timeout, int core) { // set callbacks esp_mqtt_status_callback = scb; esp_mqtt_message_callback = mcb; + + // set settings esp_mqtt_buffer_size = buffer_size; esp_mqtt_command_timeout = (uint32_t)command_timeout; + esp_mqtt_core = core; // allocate buffers esp_mqtt_write_buffer = malloc((size_t)buffer_size); @@ -553,7 +557,7 @@ bool esp_mqtt_start(const char *host, const char *port, const char *client_id, c // create mqtt thread ESP_LOGI(ESP_MQTT_LOG_TAG, "esp_mqtt_start: create task"); BaseType_t ret = xTaskCreatePinnedToCore(esp_mqtt_run, "esp_mqtt", CONFIG_ESP_MQTT_TASK_STACK, NULL, - CONFIG_ESP_MQTT_TASK_PRIORITY, &esp_mqtt_task, CONFIG_ESP_MQTT_TASK_CORE); + CONFIG_ESP_MQTT_TASK_PRIORITY, &esp_mqtt_task, esp_mqtt_core); if (ret != pdPASS) { ESP_LOGW(ESP_MQTT_LOG_TAG, "esp_mqtt_start: failed to create task"); ESP_MQTT_UNLOCK_MAIN(); diff --git a/esp_mqtt.h b/esp_mqtt.h index 44896b8..a2f6fad 100644 --- a/esp_mqtt.h +++ b/esp_mqtt.h @@ -33,9 +33,10 @@ typedef void (*esp_mqtt_message_callback_t)(const char *topic, const uint8_t *pa * @param mcb - The message callback. * @param buffer_size - The read and write buffer size. * @param command_timeout - The command timeout. + * @param core - The core to run the background task on. */ void esp_mqtt_init(esp_mqtt_status_callback_t scb, esp_mqtt_message_callback_t mcb, size_t buffer_size, - int command_timeout); + int command_timeout, int core); /** * Configure TLS connection. diff --git a/test/main/main.c b/test/main/main.c index 89b8f19..10c4ca5 100644 --- a/test/main/main.c +++ b/test/main/main.c @@ -133,7 +133,7 @@ void app_main() { ESP_ERROR_CHECK(esp_wifi_start()); // initialize mqtt - esp_mqtt_init(status_callback, message_callback, 256, 2000); + esp_mqtt_init(status_callback, message_callback, 256, 2000, 1); // create tasks xTaskCreatePinnedToCore(process, "process", 2048, NULL, 10, NULL, 1); diff --git a/test/sdkconfig b/test/sdkconfig index 37a29e0..f8f5bf1 100644 --- a/test/sdkconfig +++ b/test/sdkconfig @@ -1214,7 +1214,6 @@ CONFIG_WPA_MBEDTLS_CRYPTO=y CONFIG_ESP_MQTT_ENABLED=y CONFIG_ESP_MQTT_TASK_STACK=9216 CONFIG_ESP_MQTT_TASK_PRIORITY=5 -CONFIG_ESP_MQTT_TASK_CORE=1 CONFIG_ESP_MQTT_EVENT_QUEUE_SIZE=64 CONFIG_ESP_MQTT_TLS_ENABLE=y # end of esp-mqtt