Creating an MQTT client instance and then allowing connection through MOTT client to the MQTT server.
Referring to above code, for creating an instance of MQTT client, CreateMqttClient() function is invoked using MqttFactory object.
Inorder to connect to broker the MQTT client needs the signedRequestUrl.
This signedRequestUrl is generated using 4 things: Host (Iot Host Url), Region, AccessKey and Secret Key.
Code for generating signedRequest Url:
Using signedRequestUrl and the clientId the MqttClient is connected to the Mqtt Broker on port 443.
After connecting, we can publish messages to Mqtt Broker. Code for publishing messages to Mqtt Broker: For publishing the message, we need the topic on which the message is to be published. Here payload is the message.
We can also subscribe to messages from the Mqtt Broker. Code used for subscribing messages:
Handle Events for MqttClients:
Handler for message received after subscribing to messages.
All content provided on this blog is for informational purposes only. Tudip Technologies provides no endorsement and makes no representations as to accuracy, reliability, completeness, suitability or validity of any information or content on, distributed through or linked, downloaded or accessed from this site. Tudip Technologies will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use of the information on this site. All information is provided on an as-is basis without any obligation to make improvements or to correct errors or omissions. This site may contain links to other websites. Tudip Technologies makes no guarantees or promises regarding these websites and does not necessarily endorse or approve of their content. You may not modify any part of the blog. The inclusion of any part of this blog in another work, whether in printed or electronic or other form, or inclusion of any part of the blog in another website by linking, framing or otherwise without the express permission of Tudip Technologies is prohibited. This site may not be used for any illegal or illicit purpose and Tudip Technologies reserves the right, at its sole discretion and without notice of any kind, to remove anything posted to this site. By using this site, you hereby acknowledge that any reliance upon any materials shall be at your sole risk.