MQTT Publish/Subscribe Configuration

From Mikrodev Documentation
Jump to navigation Jump to search

Download Project Files

What You Need to Know Before Design

  • HIGH

Parameter Settings For MQTT

<img src="mqtt.png" width="50%" height="50%" style="display: block;margin-left: auto; margin-right: auto;"/>

  • Client mode must be defined in the TCP socket block for MQTT communication.
  • The server ip and port information are entered into the TCP socket block. The media type is selected within the block.
  • The Ena input of the TCP socket block must always be active for the duration of the communication.
  • After the TCP Socket output is connected to the I1 input of the MQTT Config, verification information such as Client ID, username and password is entered in the MQTT Config Block.
  • If Clean Session selection is activated, information is shared when there is communication between publish and brooker. If not selected, the information recorded in the communication breaks will not be sent.
  • If there is no communication between the publisher and the broker, the attempt is made to re-establish the MQTT connection in the Keep Alive after the time defined in seconds.
  • Timely triggering of I2 input of MQTT Config block is required when periodic data transmission is desired. If there is no trigger for I2 input, the information is sent to the broker according to the defined event conditions.
  • According to the information from the o0 output of MQTT Config block, it means: 0: TCP_DISCONNECTED, 1: TCP_CONNECTING, 2: MQTT_CONNECTING, 3: MQTT_CONNECTED
  • According to the information from the o1 output of MQTT Config block, it means: 0: E_MQTT_SEND_CONNPACK,1: E_MQTT_STATE_IDLE, 2: E_MQTT_STATE_SUBSCRIBING, 3: E_MQTT_STATE_PUBLISHING
  • The publish tmo information is read from o2 output of MQTT Config block.

Event Definitions in MQTT Table

<img src="mqtt_tablo.png" width="70%" height="70%" style="display: block;margin-left: auto; margin-right: auto;"/>

  • To create event definitions, click 'MQTT Table' option in 'Projects' in Mikrodiagram or Telediagram Program.
  • In the Topic to Publish section, the topic title to be published is entered. Payload type is selected. The query status of the package to be published in the QOS section is determined. If QOS 0 is selected, the status of the package to be publisher is not queried. If QOS1 is selected, it is informed that broadcast package is transmitted. If QOS2 is selected, the broker will receive feedback on the delivery of the published information. If retain is selected and the communication between publish and broker is lost, the latest information is kept in memory. When communication is established again, the last information is published. If clean session is selected in MQTT Config block, the information will not be published again even if retain is selected.
  • In the Publishtopic section, the blocks to be published are selected. By selecting the line tag, it is determined in which case the data will be sent. If Send on trigger is selected, the data will be published according to the trigger for I2 input of The MQTT Config block.
  • In the Topics to Subscribe section, a topic title is created for the tags to be subscribed. The verification status of the subscribed information is selected (QoS0, Qos1, Qos2).
  • In the Subscribe Topic section, the information to be subscribed is selected.