MQTT Publish Workflow

Figure 1. MQTT Publish Workflow


  1. From the Blocks / Signal Producer menu, choose the following inputs:
    • A pulseTrain and configure it with a Time Between Pulses of 0.5 seconds
    • A const and enter "Temperature". The double quotes surrounding Temperature indicate a string value
    • A sinusoid and set it to a frequency of .159 Hz
  2. From the Blocks/ Extensions/ IoT menu, add a JSON Create String block and link the three blocks created before to it.
  3. From the Blocks / Signal Consumer menu, add a display block and link it as the output of the JSON Create String block.
  4. Select Go.
    The JSON string appears as follows:
    Figure 2.


    The output string will be sent to IoT Studio via MQTT.
  5. From the Blocks/ Extensions/ IoT menu, add an MQTT Publish block and configure it with the information related to the EdgeDevice Thing created in IoT Studio. The required parameters are explained below:
    • Host Name: Specifies the MQTT broker address. For IoT Studio, use mqtt.swx.altairone.com.
    • Topic: Specifies the MQTT topic on which the message is to be published. It should look like spaces/{space}/things/{thingId}/properties
    • Username and Password: MQTT credentials of your Thing. They are needed to allow to send the data to your Thing. Information about how to get them can be found here.

    Default settings are used for the remaining parameters:

    • QoS: Specifies the quality of service to the server. Your choices are:
      • 0: Sends the message once with no guarantee of delivery. The server does not acknowledge delivery.
      • 1: Guarantees message delivery, but it could send duplicates. The server acknowledges delivery.
      • 2: Guarantees message delivery without duplicates. The server acknowledges delivery, then both the server and publisher discard the stored messages.
    • Port: Indicates the port that the broker is using. The default unencrypted port is 1883; the default encrypted port is 883.
    • Keep Alive: Specifies the maximum time interval between when the client finishes sending a PING message to the broker and starts to send the next PING message. The maximum time interval is 18 hours, 12 minutes, and 15 seconds. If it is set to 0, the keep alive mechanism is de-activated and Last Will and Testament is ignored. The default time interval is 60 sec.
    • Retain last message on server: Retains the last message if the publisher unexpectedly disconnects.
  6. Click GO to start sending the data to IoT Studio every 0.5 seconds.
  7. Open the EdgeDevice Thing Details panel. Open the properties-history and check how the data is being stored on the database in real time. If you open the MQTT Inspector under the Utility Belt, you can also check the incoming messages.
    Figure 3.