Skip to content

Commit

Permalink
Release semaphore from CONNECT only if TCP failed or accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Sep 4, 2018
1 parent 7412648 commit 4510438
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/apps/mqtt/esp_mqtt_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ mqtt_evt(mqtt_client_p client, mqtt_evt_t* evt) {
ESP_DEBUGF(ESP_CFG_DBG_MQTT_API_STATE, "[MQTT API] Connect event with status: %d\r\n", (int)status);

api_client->connect_resp = status;
release_sem(api_client);

/*
* By MQTT 3.1.1 specification, broker must close connection
* if client CONNECT packet was not accepted.
*
* If client is accepted or connection did not even start,
* release semaphore, otherwise wait CLOSED event
* and release semaphore from there,
* to make sure we are fully ready for next connect
*/
if (status == MQTT_CONN_STATUS_TCP_FAILED || status == MQTT_CONN_STATUS_ACCEPTED) {
release_sem(api_client);
}

break;
}
Expand Down

0 comments on commit 4510438

Please sign in to comment.