-
Notifications
You must be signed in to change notification settings - Fork 1.9k
MQTTv5 Demo Implementation #1338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| @@ -0,0 +1,1339 @@ | |||
|
|
|||
|
|
|||
| /* | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The v5 demo code should contain a similar licensing information as the previous v3 demo.
|
|
||
| /* Demo Specific configs. */ | ||
| #include "demo_config.h" | ||
| #include "core_mqtt_config.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need to include core_mqtt_config.h explicitly. It will be included through the core_mqtt.h file.
|
|
||
| /* MQTT library includes. */ | ||
| #include "core_mqtt.h" | ||
| #include "core_mqtt_utils.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we include core_mqtt_utils.h in the core_mqtt_serializer.h then we do not need to make this extra include here. This will be one less change that the user needs to do while migrating from v3 to v5.
| #define mqttexampleCONNACK_RECV_TIMEOUT_MS ( 100000U ) | ||
|
|
||
| /** | ||
| * @brief The prefix to the topic(s) subscribe(d) to and publish(ed) to in the example. | ||
| * | ||
| * The topic name starts with the client identifier to ensure that each demo | ||
| * interacts with a unique topic name. | ||
| */ | ||
| #define mqttexampleTOPIC_PREFIX "test" | ||
|
|
||
| /** | ||
| * @brief The number of topic filters to subscribe. | ||
| */ | ||
| #define mqttexampleTOPIC_COUNT ( 2 ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we are done with the testing, we should change these values back to the original values present in the v3 demo.
...OS-Plus/Demo/coreMQTT_Windows_Simulator/MQTTV5_Plain_Text/DemoTasks/PlaintextMQTTExampleV5.c
Outdated
Show resolved
Hide resolved
| MQTTContext_t xMQTTContext = { 0 }; | ||
| MQTTStatus_t xMQTTStatus; | ||
| PlaintextTransportStatus_t xNetworkStatus; | ||
| MQTTConnectProperties_t xProperties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we have added the MQTTConnectProperties in the Context itself, we do not need this variable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree, It has been removed
| MQTTStatus_t xMQTTStatus; | ||
| PlaintextTransportStatus_t xNetworkStatus; | ||
| MQTTConnectProperties_t xProperties; | ||
| MQTTReasonCodeInfo_t disconnect = { 0 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we require this MQTTReasonCodeInfo_t disconnect = { 0 }; variable?
...OS-Plus/Demo/coreMQTT_Windows_Simulator/MQTTV5_Plain_Text/DemoTasks/PlaintextMQTTExampleV5.c
Outdated
Show resolved
Hide resolved
| MQTTReasonCodeInfo_t disconnect; | ||
| PlaintextTransportStatus_t xNetworkStatus; | ||
| MQTTPublishInfo_t willInfo; | ||
| MQTTAuthInfo_t auth; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see the disconnect, xNetworkStatus and auth vairables being used in this function. If they are not to be used, we can remove them from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
|
|
||
| MqttPropBuilder_t propBuilder; | ||
| uint8_t buf[500]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good practice to use macros instead of direct contants, so that the reader of the code (which will be a user in case of a demo) can understand what this macro is for. We should define a macro in this demo file, something like MAX_PROPERTY_BUFFER_LENGTH, and map it to a constant like 500 in this case. The user can change this macro if they wish to.
|
|
||
|
|
||
| xResult = MQTTPropAdd_UserProp(&(propBuilder), &xUserProperty); | ||
| xResult = MQTTPropAdd_ConnSessionExpiry(&(propBuilder), sessionExpiry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be asserts after each of these lines like assert( xResult == MQTTSuccess )
| //xResult = MQTTPropAdd_ConnAuthMethod(&(propBuilder), "SCRAM-SHA-1 ", 11); | ||
| //xResult = MQTTPropAdd_ConnAuthData(&(propBuilder), "test", 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove all the code that is not needed and is commented out.
...OS-Plus/Demo/coreMQTT_Windows_Simulator/MQTTV5_Plain_Text/DemoTasks/PlaintextMQTTExampleV5.c
Outdated
Show resolved
Hide resolved
...OS-Plus/Demo/coreMQTT_Windows_Simulator/MQTTV5_Plain_Text/DemoTasks/PlaintextMQTTExampleV5.c
Outdated
Show resolved
Hide resolved
...OS-Plus/Demo/coreMQTT_Windows_Simulator/MQTTV5_Plain_Text/DemoTasks/PlaintextMQTTExampleV5.c
Outdated
Show resolved
Hide resolved
…eeRTOS into pooja-main-branch
|
The changes in this PR are moved to the PR #1354. Hence closing this PR. Thanks. |
Upgrading MQTT Demos to support v5 features
Description
This PR adds a demo application to showcase MQTT version 5.0 functionality using the coreMQTT library. It demonstrates establishing a connection with a broker, subscribing to a topic, publishing a message, receiving Incoming publishes, unsubscribing from a topic, and finally disconnecting.
Existing data structures and functions are modified, and some new functions are added.
Test Steps
Checklist:
Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.