Examples: Building MQTT client steps

This section provides a step-by-step guide to building an MQTT client with examples.
Creating an MQTT client to a broker needs the following steps and at least two buttons on a display, one for subscribing and the other for publishing.
  1. Create an instance of MQTTFactory to create MQTTClient.
    Option Explicit Private mFactory As MQTTFactory Private WithEvents mClient As MQTTClient
  2. Set up the connection options, such as client ID and broker's address. Change
    broker.com
    to your broker's address and port.
    Copy one of the following MQTT examples and edit per your needs, and then you can call the function, for example
    Connect_WithTCP
    , to create an MQTT client at Display_AnimationStart.
  3. Subscribe to a topic.
    Copy the following MQTT example and edit per your needs, and then you can use the subscribing button to call the function to subscribe to a topic.
  4. Set up a message handler to process incoming messages.
    Copy the following MQTT example and edit per your needs.
  5. Publish a message and send it to the specific topic.
    Copy the following MQTT example and edit per your needs, and then you can use the publishing button to call the function to publish a message.
  6. Test run the display to connect to the broker, and then click the subscribing button and the publishing button to subscribe to and publish a message.
You can use the following MQTT examples to handle errors per your needs.
For more information about MQTT advanced properties, refer to a ready-made graphic display with the pre-configured MQTT objects called
MQTT
, which is installed in
Graphics
>
Libraries
.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal