espressif / esp-mqtt

ESP32 mqtt component
Apache License 2.0
603 stars 255 forks source link

getting incorrect packet id for MQTT_MSG_TYPE_UNSUBSCRIBE from mqtt_get_id function in mqtt_msg.c since it is not listed in switch case. #109

Closed Suraj151 closed 5 years ago

david-cermak commented 5 years ago

Hi @Suraj151

Thanks for noting this inconsistency. Does it cause any issue in current implementation? I can see that mqtt_get_id is used mainly in processing of received messages (so it's not expected to get a subscribe/unsubsribe message in the client).

Suraj151 commented 5 years ago

it matters as we checks for pending msg id in receive function that was assigned to packet before send and on success of this checks we call unsubscribe callbacks to remove unsubscribed topic from subscribed topic queue. and if you don't get correct msg id then your check fails and abort next callback process. that issue i faced.

david-cermak commented 5 years ago

So that you call mqtt_get_id from your application code? Using a private include or am I missing something?

I'm sorry, surly this needs to fixed, but I would like to understand the issue and your use case.

Suraj151 commented 5 years ago

right ! i called mqtt_get_id from my application code.

i have a queue that keeps track about subscribed topics and it get updated from subscribe & unsubscribe callbacks.these callbacks called from received responses from mqtt broker.

Since my application needs dynamically subscribe and unsubscribe topics on periodic basis i need to keep track of subscribed and unsubscribed topics.

there is another queue where i push next topics to be subscribed and unsubscribed. when this queue get processed (i.e. sending of subscribe and unsubscribe packets) i assigned them with unique runtime msg ids those requires later to check on response from broker. on this id checks it calls subscribe and unsubscribe callbacks.

i got subscribe id correctly in response check but not unsubscribed ones. on debugging some i get to know about subjected issue. after adding unsubscribe type in switch case i get unsubscribe id correctly and my subscribed topic queue gets updated correctly.

so i just informed here this.

david-cermak commented 5 years ago

ok, understand, thanks for explaining your use case. will correct the switch case.