mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-30 10:48:06 +02:00
MQTT: fix MQTT_PUBLISHED_EVENT not always being posted
- Some PUBLISHED events would not be posted due to outbox messages being deleted before receiving PUBCOMP. - Current pending_message is no longer used to check for acknowledgements, as it doesn't work with multiple or out of order messages. Closes https://github.com/espressif/esp-mqtt/issues/132
This commit is contained in:
committed by
David Cermak
parent
78e2a7050e
commit
3e35fc8323
@ -30,6 +30,7 @@ typedef struct outbox_message {
|
||||
typedef enum pending_state {
|
||||
QUEUED,
|
||||
TRANSMITTED,
|
||||
ACKNOWLEDGED,
|
||||
CONFIRMED
|
||||
} pending_state_t;
|
||||
|
||||
|
@ -682,10 +682,6 @@ static bool is_valid_mqtt_msg(esp_mqtt_client_handle_t client, int msg_type, int
|
||||
client->mqtt_state.pending_msg_count --;
|
||||
return true;
|
||||
}
|
||||
if (client->mqtt_state.pending_msg_type == msg_type && client->mqtt_state.pending_msg_id == msg_id) {
|
||||
client->mqtt_state.pending_msg_count --;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -935,7 +931,7 @@ static esp_err_t mqtt_process_receive(esp_mqtt_client_handle_t client)
|
||||
case MQTT_MSG_TYPE_PUBREC:
|
||||
ESP_LOGD(TAG, "received MQTT_MSG_TYPE_PUBREC");
|
||||
client->mqtt_state.outbound_message = mqtt_msg_pubrel(&client->mqtt_state.mqtt_connection, msg_id);
|
||||
outbox_set_pending(client->outbox, msg_id, CONFIRMED);
|
||||
outbox_set_pending(client->outbox, msg_id, ACKNOWLEDGED);
|
||||
mqtt_write_data(client);
|
||||
break;
|
||||
case MQTT_MSG_TYPE_PUBREL:
|
||||
@ -947,6 +943,7 @@ static esp_err_t mqtt_process_receive(esp_mqtt_client_handle_t client)
|
||||
ESP_LOGD(TAG, "received MQTT_MSG_TYPE_PUBCOMP");
|
||||
if (is_valid_mqtt_msg(client, MQTT_MSG_TYPE_PUBLISH, msg_id)) {
|
||||
ESP_LOGD(TAG, "Receive MQTT_MSG_TYPE_PUBCOMP, finish QoS2 publish");
|
||||
outbox_set_pending(client->outbox, msg_id, CONFIRMED);
|
||||
client->event.event_id = MQTT_EVENT_PUBLISHED;
|
||||
esp_mqtt_dispatch_event_with_msgid(client);
|
||||
}
|
||||
|
Reference in New Issue
Block a user