MQTT is the most widely used and known protocol for IoT devices. Let's have a basic look at MQTT and how could we use it with IoTIFY
The MQTT protocol is based on TCP and is one of the most commonly used publish/subscribe protocols in use today. For a detailed overview of MQTT let's refer you to the Hivemq tutorial which has covered this subject pretty well.
Introducing the MQTT Protocol - MQTT Essentials: Part 1
What should you know about MQTT?
  1. 1.
    MQTT requires that all client connect to a broker. There are several public broker available today and you could launch your own MQTT broker as well.
  2. 2.
    The clients of MQTT publish data on the topics which are hierarchical in nature. E.g. A topic could be formed for a university as follows:
    • /university/
    • /university/EECS/
    • /university/MECH/
  3. 3.
    MQTT protocol provides three quality of service(QoS) levels:
    1. 1.
      QoS 0: at most once
    2. 2.
      QoS 1: at least once
    3. 3.
      QoS 2: exactly once

Overview of MQTT Template Settings

Snapshot of the MQTT settings
In the protocol tab, you can modify several settings for the MQTT Protocol:
MQTT Endpoint: The name or IP address of the server along with the port number. It must be a public server IP address that is reachable over the internet.
Keep Alive: The keepalive timer duration for the protocol. The hello message is sent every keepalive interval to make sure the server is aware of the client being connected.
QoS: QoS settings ensure that the delivery of the message is guaranteed. Higher the QoS Settings more will be the latency of packet sending as the server will need to ensure that the messages are delivered with a guarantee.
Retain: Whether the server should retain the messages for a future delivery.
Publication Topic: The topic on which messages should be published. The topic field is scriptable, i.e. you could use template strings in Topic to dynamically change the content of the topic. For example,
/iotify/temperature/{{client()}} // will translate to /iotify/temperature/0
Any field within {{ }} will be evaluated at runtime and will be replaced with the actual contents.
Will change to whatever state.topic variable value is at the run time. For performance reasons, make sure that the fields are not too complex.
Subscription Topic: (Can be enabled when required) The topic to which the client should subscribe. This field is scriptable but only at the beginning of the simulation (after the Init stage). For example, if you use {{state.topic}} within the Subscription Topic string, the subscription will be initialized to whatever value the topic had past the Init stage. However, the content will not change as the simulation runs.
Timeout: The timeout value to establish a connection with the server and wait for the messages to be sent. If the operation doesn't complete within the timeout period, it is marked as failed.
Security: If the connection to the server requires authentication, the required fields can be passed here. For MQTT connection we support:
  • Username and Password combination
  • Pre-Shared Keys
  • Certificates