mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-08-01 11:45:11 +02:00
Merge branch 'feature/mqtt_client_with_null_id' into 'master'
Adds the possibilty of client with empty id See merge request espressif/esp-mqtt!114
This commit is contained in:
@@ -17,6 +17,13 @@ before_script:
|
|||||||
# Use CI Tools
|
# Use CI Tools
|
||||||
- curl -sSL ${CIT_LOADER_URL} | sh
|
- curl -sSL ${CIT_LOADER_URL} | sh
|
||||||
- source citools/import_functions
|
- source citools/import_functions
|
||||||
|
# Add gitlab ssh key
|
||||||
|
- mkdir -p ~/.ssh
|
||||||
|
- chmod 700 ~/.ssh
|
||||||
|
- echo -n $GITLAB_KEY > ~/.ssh/id_rsa_base64
|
||||||
|
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
|
||||||
|
- chmod 600 ~/.ssh/id_rsa
|
||||||
|
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
||||||
- PATH=$CI_PROJECT_DIR/esp-idf/tools:$PATH
|
- PATH=$CI_PROJECT_DIR/esp-idf/tools:$PATH
|
||||||
- export IDF_PATH=$CI_PROJECT_DIR/esp-idf
|
- export IDF_PATH=$CI_PROJECT_DIR/esp-idf
|
||||||
- export MQTT_PATH=$CI_PROJECT_DIR
|
- export MQTT_PATH=$CI_PROJECT_DIR
|
||||||
@@ -28,7 +35,6 @@ build_with_idf_v3:
|
|||||||
- build
|
- build
|
||||||
dependencies: []
|
dependencies: []
|
||||||
script:
|
script:
|
||||||
- cit_add_ssh_key "${GITLAB_KEY}"
|
|
||||||
- git clone "${IDF_REPO}"
|
- git clone "${IDF_REPO}"
|
||||||
# build with IDFv3.2
|
# build with IDFv3.2
|
||||||
- $MQTT_PATH/ci/set_idf.sh release/v3.2
|
- $MQTT_PATH/ci/set_idf.sh release/v3.2
|
||||||
@@ -53,7 +59,6 @@ build_with_idf_v4:
|
|||||||
variables:
|
variables:
|
||||||
PYTHON_VER: 3.6.13
|
PYTHON_VER: 3.6.13
|
||||||
script:
|
script:
|
||||||
- cit_add_ssh_key "${GITLAB_KEY}"
|
|
||||||
- git clone "${IDF_REPO}"
|
- git clone "${IDF_REPO}"
|
||||||
- source /opt/pyenv/activate && pyenv global $PYTHON_VER
|
- source /opt/pyenv/activate && pyenv global $PYTHON_VER
|
||||||
- $MQTT_PATH/ci/set_idf.sh master
|
- $MQTT_PATH/ci/set_idf.sh master
|
||||||
@@ -105,7 +110,6 @@ build_and_test_qemu:
|
|||||||
variables:
|
variables:
|
||||||
PYTHON_VER: 3.6.13
|
PYTHON_VER: 3.6.13
|
||||||
script:
|
script:
|
||||||
- cit_add_ssh_key "${GITLAB_KEY}"
|
|
||||||
- git clone "${IDF_REPO}"
|
- git clone "${IDF_REPO}"
|
||||||
- source /opt/pyenv/activate && pyenv global $PYTHON_VER
|
- source /opt/pyenv/activate && pyenv global $PYTHON_VER
|
||||||
# switch to IDF and setup the tools
|
# switch to IDF and setup the tools
|
||||||
|
@@ -176,7 +176,11 @@ typedef struct {
|
|||||||
const char *host; /*!< MQTT server domain (ipv4 as string) */
|
const char *host; /*!< MQTT server domain (ipv4 as string) */
|
||||||
const char *uri; /*!< Complete MQTT broker URI */
|
const char *uri; /*!< Complete MQTT broker URI */
|
||||||
uint32_t port; /*!< MQTT server port */
|
uint32_t port; /*!< MQTT server port */
|
||||||
const char *client_id; /*!< default client id is ``ESP32_%CHIPID%`` where %CHIPID% are last 3 bytes of MAC address in hex format */
|
bool set_null_client_id; /*!< Selects a NULL client id */
|
||||||
|
const char *client_id; /*!< Set client id.
|
||||||
|
Ignored if set_null_client_id == true
|
||||||
|
If NULL set the default client id.
|
||||||
|
Default client id is ``ESP32_%CHIPID%`` where %CHIPID% are last 3 bytes of MAC address in hex format */
|
||||||
const char *username; /*!< MQTT username */
|
const char *username; /*!< MQTT username */
|
||||||
const char *password; /*!< MQTT password */
|
const char *password; /*!< MQTT password */
|
||||||
const char *lwt_topic; /*!< LWT (Last Will and Testament) message topic (NULL by default) */
|
const char *lwt_topic; /*!< LWT (Last Will and Testament) message topic (NULL by default) */
|
||||||
|
@@ -361,7 +361,7 @@ mqtt_message_t *mqtt_msg_connect(mqtt_connection_t *connection, mqtt_connect_inf
|
|||||||
if (connection->message.length + header_len > connection->buffer_length) {
|
if (connection->message.length + header_len > connection->buffer_length) {
|
||||||
return fail_message(connection);
|
return fail_message(connection);
|
||||||
}
|
}
|
||||||
char* variable_header = (void *)(connection->buffer + connection->message.length);
|
char *variable_header = (char *)(connection->buffer + connection->message.length);
|
||||||
connection->message.length += header_len;
|
connection->message.length += header_len;
|
||||||
|
|
||||||
int header_idx = 0;
|
int header_idx = 0;
|
||||||
@@ -394,7 +394,9 @@ mqtt_message_t *mqtt_msg_connect(mqtt_connection_t *connection, mqtt_connect_inf
|
|||||||
return fail_message(connection);
|
return fail_message(connection);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return fail_message(connection);
|
if (append_string(connection, "", 0) < 0) {
|
||||||
|
return fail_message(connection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->will_topic != NULL && info->will_topic[0] != '\0') {
|
if (info->will_topic != NULL && info->will_topic[0] != '\0') {
|
||||||
@@ -456,7 +458,7 @@ mqtt_message_t *mqtt_msg_publish(mqtt_connection_t *connection, const char *topi
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data == NULL && data_length > 0) {
|
if (data == NULL && data_length > 0) {
|
||||||
return fail_message(connection);
|
return fail_message(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qos > 0) {
|
if (qos > 0) {
|
||||||
@@ -474,8 +476,7 @@ mqtt_message_t *mqtt_msg_publish(mqtt_connection_t *connection, const char *topi
|
|||||||
connection->message.length = connection->buffer_length;
|
connection->message.length = connection->buffer_length;
|
||||||
connection->message.fragmented_msg_total_length = data_length + connection->message.fragmented_msg_data_offset;
|
connection->message.fragmented_msg_total_length = data_length + connection->message.fragmented_msg_data_offset;
|
||||||
} else {
|
} else {
|
||||||
if (data != NULL)
|
if (data != NULL) {
|
||||||
{
|
|
||||||
memcpy(connection->buffer + connection->message.length, data, data_length);
|
memcpy(connection->buffer + connection->message.length, data, data_length);
|
||||||
connection->message.length += data_length;
|
connection->message.length += data_length;
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,6 @@ ESP_EVENT_DEFINE_BASE(MQTT_EVENTS);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct mqtt_state {
|
typedef struct mqtt_state {
|
||||||
mqtt_connect_info_t *connect_info;
|
|
||||||
uint8_t *in_buffer;
|
uint8_t *in_buffer;
|
||||||
uint8_t *out_buffer;
|
uint8_t *out_buffer;
|
||||||
int in_buffer_length;
|
int in_buffer_length;
|
||||||
@@ -372,7 +371,7 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
|||||||
|
|
||||||
client->config->message_retransmit_timeout = config->message_retransmit_timeout;
|
client->config->message_retransmit_timeout = config->message_retransmit_timeout;
|
||||||
if (config->message_retransmit_timeout <= 0) {
|
if (config->message_retransmit_timeout <= 0) {
|
||||||
client->config->message_retransmit_timeout = 1000;
|
client->config->message_retransmit_timeout = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
client->config->task_prio = config->task_prio;
|
client->config->task_prio = config->task_prio;
|
||||||
@@ -395,13 +394,15 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
|||||||
ESP_MEM_CHECK(TAG, set_if_config(config->username, &client->connect_info.username), goto _mqtt_set_config_failed);
|
ESP_MEM_CHECK(TAG, set_if_config(config->username, &client->connect_info.username), goto _mqtt_set_config_failed);
|
||||||
ESP_MEM_CHECK(TAG, set_if_config(config->password, &client->connect_info.password), goto _mqtt_set_config_failed);
|
ESP_MEM_CHECK(TAG, set_if_config(config->password, &client->connect_info.password), goto _mqtt_set_config_failed);
|
||||||
|
|
||||||
if (config->client_id) {
|
if (!config->set_null_client_id) {
|
||||||
ESP_MEM_CHECK(TAG, set_if_config(config->client_id, &client->connect_info.client_id), goto _mqtt_set_config_failed);
|
if (config->client_id) {
|
||||||
} else if (client->connect_info.client_id == NULL) {
|
ESP_MEM_CHECK(TAG, set_if_config(config->client_id, &client->connect_info.client_id), goto _mqtt_set_config_failed);
|
||||||
client->connect_info.client_id = platform_create_id_string();
|
} else if (client->connect_info.client_id == NULL) {
|
||||||
|
client->connect_info.client_id = platform_create_id_string();
|
||||||
|
}
|
||||||
|
ESP_MEM_CHECK(TAG, client->connect_info.client_id, goto _mqtt_set_config_failed);
|
||||||
|
ESP_LOGD(TAG, "MQTT client_id=%s", client->connect_info.client_id);
|
||||||
}
|
}
|
||||||
ESP_MEM_CHECK(TAG, client->connect_info.client_id, goto _mqtt_set_config_failed);
|
|
||||||
ESP_LOGD(TAG, "MQTT client_id=%s", client->connect_info.client_id);
|
|
||||||
|
|
||||||
ESP_MEM_CHECK(TAG, set_if_config(config->uri, &client->config->uri), goto _mqtt_set_config_failed);
|
ESP_MEM_CHECK(TAG, set_if_config(config->uri, &client->config->uri), goto _mqtt_set_config_failed);
|
||||||
ESP_MEM_CHECK(TAG, set_if_config(config->lwt_topic, &client->connect_info.will_topic), goto _mqtt_set_config_failed);
|
ESP_MEM_CHECK(TAG, set_if_config(config->lwt_topic, &client->connect_info.will_topic), goto _mqtt_set_config_failed);
|
||||||
@@ -427,6 +428,9 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
|||||||
|
|
||||||
if (config->disable_clean_session == client->connect_info.clean_session) {
|
if (config->disable_clean_session == client->connect_info.clean_session) {
|
||||||
client->connect_info.clean_session = !config->disable_clean_session;
|
client->connect_info.clean_session = !config->disable_clean_session;
|
||||||
|
if (!client->connect_info.clean_session && config->set_null_client_id) {
|
||||||
|
ESP_LOGE(TAG, "Clean Session flag must be true if client has a null id");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (config->keepalive) {
|
if (config->keepalive) {
|
||||||
client->connect_info.keepalive = config->keepalive;
|
client->connect_info.keepalive = config->keepalive;
|
||||||
@@ -623,7 +627,7 @@ static esp_err_t esp_mqtt_connect(esp_mqtt_client_handle_t client, int timeout_m
|
|||||||
int read_len, connect_rsp_code;
|
int read_len, connect_rsp_code;
|
||||||
client->wait_for_ping_resp = false;
|
client->wait_for_ping_resp = false;
|
||||||
client->mqtt_state.outbound_message = mqtt_msg_connect(&client->mqtt_state.mqtt_connection,
|
client->mqtt_state.outbound_message = mqtt_msg_connect(&client->mqtt_state.mqtt_connection,
|
||||||
client->mqtt_state.connect_info);
|
&client->connect_info);
|
||||||
if (client->mqtt_state.outbound_message->length == 0) {
|
if (client->mqtt_state.outbound_message->length == 0) {
|
||||||
ESP_LOGE(TAG, "Connect message cannot be created");
|
ESP_LOGE(TAG, "Connect message cannot be created");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
@@ -791,7 +795,6 @@ esp_mqtt_client_handle_t esp_mqtt_client_init(const esp_mqtt_client_config_t *co
|
|||||||
ESP_MEM_CHECK(TAG, client->mqtt_state.out_buffer, goto _mqtt_init_failed);
|
ESP_MEM_CHECK(TAG, client->mqtt_state.out_buffer, goto _mqtt_init_failed);
|
||||||
|
|
||||||
client->mqtt_state.out_buffer_length = out_buffer_size;
|
client->mqtt_state.out_buffer_length = out_buffer_size;
|
||||||
client->mqtt_state.connect_info = &client->connect_info;
|
|
||||||
client->outbox = outbox_init();
|
client->outbox = outbox_init();
|
||||||
ESP_MEM_CHECK(TAG, client->outbox, goto _mqtt_init_failed);
|
ESP_MEM_CHECK(TAG, client->outbox, goto _mqtt_init_failed);
|
||||||
client->status_bits = xEventGroupCreate();
|
client->status_bits = xEventGroupCreate();
|
||||||
|
Reference in New Issue
Block a user