From a262731f92e84c74f7ab34914067f243a933e263 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sun, 10 Mar 2019 13:46:43 +0100 Subject: [PATCH] Increment publish packet id, as to consecutive packet must not have the same packet ID Fix return values. --- mqtt_pub/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mqtt_pub/main.c b/mqtt_pub/main.c index e6b73a4..d96ba07 100644 --- a/mqtt_pub/main.c +++ b/mqtt_pub/main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/base/mqtt/main.c + * apps/base/mqtt_pub/main.c * * MQTT client example using data from onboard TMP101 I2C temperature sensor * @@ -273,6 +273,7 @@ int mqtt_handle_packet(char* buf, int comm_uart, int dbg_uart) } else { uprintf(dbg_uart, "Connection refused: %d\n", response->ret_code); mqtt_comm_state = MQTT_UNCONNECTED; + return -4; } break; } @@ -281,9 +282,15 @@ int mqtt_handle_packet(char* buf, int comm_uart, int dbg_uart) ret = mqtt_check_publish_response_pkt(response, MQTT_WAITING_PUBACK); if (ret != 0) { uprintf(dbg_uart, "Not a connack packet (ret: %d) ... protocol flow error\n", ret); - return -3; + return -5; + } + if (response->acked_pkt_id != pub_packet_id) { + uprintf(dbg_uart, "Not a connack for the right packet (got %d, our is %d) ...\n", + response->acked_pkt_id, pub_packet_id); + return -6; } mqtt_comm_state = MQTT_IDLE; + pub_packet_id++; break; } case MQTT_WAITING_PUBREC: @@ -384,6 +391,9 @@ int main(void) /* Check for received packet on serial line and handle them */ if (packet_ok != NULL) { int ret = mqtt_handle_packet((char*)packet_ok, UART0, UART0); + if (ret != 0) { + uprintf(UART0, "Packet handling returned error %d\n", ret); + } packet_ok = NULL; } chenillard(250); -- 2.43.0