diff --git a/include/mqtt_client.h b/include/mqtt_client.h index 37f416a..c90b2f7 100644 --- a/include/mqtt_client.h +++ b/include/mqtt_client.h @@ -165,7 +165,7 @@ typedef struct { void *user_context; /*!< pass user context to this option, then can receive that context in ``event->user_context`` */ int task_prio; /*!< MQTT task priority, default is 5, can be changed in ``make menuconfig`` */ int task_stack; /*!< MQTT task stack size, default is 6144 bytes, can be changed in ``make menuconfig`` */ - int buffer_size; /*!< size of MQTT send/receive buffer, default is 1024 */ + int buffer_size; /*!< size of MQTT send/receive buffer, default is 1024 (only receive buffer size if ``out_buffer_size`` defined) */ const char *cert_pem; /*!< Pointer to certificate data in PEM or DER format for server verify (with SSL), default is NULL, not required to verify the server. PEM-format must have a terminating NULL-character. DER-format requires the length to be passed in cert_len. */ size_t cert_len; /*!< Length of the buffer pointed to by cert_pem. May be 0 for null-terminated pem */ const char *client_cert_pem; /*!< Pointer to certificate data in PEM or DER format for SSL mutual authentication, default is NULL, not required if mutual authentication is not needed. If it is not NULL, also `client_key_pem` has to be provided. PEM-format must have a terminating NULL-character. DER-format requires the length to be passed in client_cert_len. */ @@ -181,6 +181,7 @@ typedef struct { const char *clientkey_password; /*!< Client key decryption password string */ int clientkey_password_len; /*!< String length of the password pointed to by clientkey_password */ esp_mqtt_protocol_ver_t protocol_ver; /*!< MQTT protocol version used for connection, defaults to value from menuconfig*/ + int out_buffer_size; /*!< size of MQTT output buffer. If not defined, both output and input buffers have the same size defined as ``buffer_size`` */ } esp_mqtt_client_config_t; /** diff --git a/mqtt_client.c b/mqtt_client.c index 3ee2028..9372512 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -654,14 +654,16 @@ esp_mqtt_client_handle_t esp_mqtt_client_init(const esp_mqtt_client_config_t *co if (buffer_size <= 0) { buffer_size = MQTT_BUFFER_SIZE_BYTE; } + // use separate value for output buffer size if configured + int out_buffer_size = config->out_buffer_size > 0 ? config->out_buffer_size : buffer_size; client->mqtt_state.in_buffer = (uint8_t *)malloc(buffer_size); ESP_MEM_CHECK(TAG, client->mqtt_state.in_buffer, goto _mqtt_init_failed); client->mqtt_state.in_buffer_length = buffer_size; - client->mqtt_state.out_buffer = (uint8_t *)malloc(buffer_size); + client->mqtt_state.out_buffer = (uint8_t *)malloc(out_buffer_size); ESP_MEM_CHECK(TAG, client->mqtt_state.out_buffer, goto _mqtt_init_failed); - client->mqtt_state.out_buffer_length = buffer_size; + client->mqtt_state.out_buffer_length = out_buffer_size; client->mqtt_state.connect_info = &client->connect_info; client->outbox = outbox_init(); ESP_MEM_CHECK(TAG, client->outbox, goto _mqtt_init_failed);