-
Notifications
You must be signed in to change notification settings - Fork 642
[PR from CLI tool] Add MQTT demo for connection sharing with subscription manager #1098
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
[PR from CLI tool] Add MQTT demo for connection sharing with subscription manager #1098
Conversation
…; update config files and CMakeLists.txt for demo
…T_PATH macro with absolute path of downloaded certificate, and update demo_config files to have #ifndef guards around the macro
Codecov Report
@@ Coverage Diff @@
## development #1098 +/- ##
===============================================
+ Coverage 96.54% 98.76% +2.21%
===============================================
Files 9 4 -5
Lines 5643 1371 -4272
Branches 641 418 -223
===============================================
- Hits 5448 1354 -4094
+ Misses 9 0 -9
+ Partials 186 17 -169
Continue to review full report at Codecov.
|
…o/mqtt-connection-sharing
Co-authored-by: Muneeb Ahmed <54290492+muneebahmed10@users.noreply.github.com>
…t-device-sdk-embedded-C into add-subscription-manager
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
… functions based on review feedback
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
|
|
||
| /*-----------------------------------------------------------*/ | ||
|
|
||
| static int publishToTopic( MQTTContext_t * pMqttContext, |
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.
Since this function now not only publishes to a topic, but receives publishes from the broker, its name should be updated
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.
This function is only used for sending publishes to broker, and not for receiving incoming PUBLISHes
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.
On line 1186, you use this function for receiving incoming publishes with the call to MQTT_ProcessLoop(). Otherwise, the check on line 1283 for receiving the temperature data would fail.
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.
Ahh, okay good point! Have renamed the function to publishToTopicAndProcessIncomingMessage
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
|
|
||
| /* Process Incoming UNSUBACK packet from the broker. */ | ||
| mqttStatus = MQTT_ProcessLoop( pMqttContext, MQTT_PROCESS_LOOP_TIMEOUT_MS ); | ||
|
|
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.
Would it be useful to have a global receivedUnsuback flag? If we do, we don't have to wait the entire timeout and can just wait until we receive the unsuback. If not, I don't really see why this function needs to call the process loop. Since we have three consecutive unsubscribeFromTopic calls, It would save 2 * MQTT_PROCESS_LOOP_TIMEOUT_MS milliseconds If we only called the process loop once after all three calls.
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 can instead unsubscribe from all topic filters in the same UNSUBSCRIBE request
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.
Have updated the private function to take in a list of topic filters to unsubscribe with a single packet.
| * publish to. | ||
| * | ||
| * The topic name starts with the client identifier to ensure that each demo | ||
| * interacts with a unique topic name. |
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'm a little confused by this, so maybe this comment could have more clarification. Why does each demo need a unique topic name, and how does the client identifier make it unique? If it's for the case of a customer choosing to use a public broker like test.mosquitto.org instead of a local broker, we could mention that's the reason.
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's a copy-pasta from other demos. Now, that we have moved away from using the public broker, I agree that we can avoid this comment
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 prefer that we don't mention about the test.mosquitto.org due to its reliability concerns.
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| /* Copy the available index into the output param. */ | ||
| *pIndex = index; |
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.
Nit: would it make more sense to only set this on success?
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.
Made the improvement in the basic TLS demo (as have removed the feature of publish resend from this demo)
|
|
||
| /* Sends an MQTT Connect packet using the established TLS session, | ||
| * then waits for connection acknowledgment (CONNACK) packet. */ | ||
| returnStatus = establishMqttSession( &mqttContext, pNetworkContext, false, &sessionPresent ); |
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 understand if this was a requirement for this demo, but if it was only a design choice, does this demo need non-clean sessions? I feel like connection sharing and resending of publishes are separate features, and if we already show it in the TLS and mutual auth demos, then we don't need to show it again here. It would reduce the amount of code that's duplicated in multiple places.
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.
That's a good suggestion in terms of reducing the number of lines of code in this demo. I have removed the session restore feature (of resending publish messages) from this demo.
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
| /* Wait for acknowledgement packet (SUBACK) from the broker in response to the | ||
| * subscribe request. */ | ||
| mqttStatus = MQTT_ProcessLoop( pMqttContext, MQTT_PROCESS_LOOP_TIMEOUT_MS ); | ||
|
|
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.
If the intention here is to make sure the SUBACK was received, we could add a flag that's set in the event callback on SUBACK reception. Just a thought, I don't expect it to be changed for this PR.
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.
If the suggestion is to call ProcessLoop avoid the large timeout value, we can consider that for a separate PR effort.
Co-authored-by: Muneeb Ahmed <54290492+muneebahmed10@users.noreply.github.com>
| * @brief The MQTT message for the #DEMO_TEMPERATURE_HIGH_TOPIC topic published | ||
| * in this example. | ||
| */ | ||
| #define DEMO_TEMPERATURE_HIGH_MESSAGE "Today's High is 80 degree F" |
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.
Perhaps we should use this opportunity to push Kelvin as the superior unit of measurement
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.
Interesting point (to make the demo universally appealing) 😆
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.
Approved, see comments. It looks like some of this demo code could be refactored out into a helpful library which many applications could use; not a blocker but something to think about.
demos/mqtt/mqtt_demo_connection_sharing/mqtt_demo_connection_sharing.c
Outdated
Show resolved
Hide resolved
| * when a MQTT connection is established with a session that was already | ||
| * present. All the outgoing publish messages waiting to receive PUBACK | ||
| * are resent in this demo. In order to support retransmission all the outgoing | ||
| * publishes are stored until a PUBACK is received. |
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.
Unless I've missed something retransmission won't work across reboots, so you may want to mention this in the comments.
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 have removed the text about re-transmission as I removed all the re-transmission related code from this demo to avoid code duplication across our demo files
MQTT demo for using subscription manager when sharing MQTT connection among multiple subscription topics
Description of changes:
MQTT_MatchTopicfunction (that is added in [PR from CLI tool] Add utility for MQTT topic filter and topic matching to library #1119)By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.