Updated on 2023-11-08 GMT+08:00

Before You Start

Introduction

An MQTT message consists of fixed header, variable header, and payload.

For details on how to define the fixed header and variable header, see MQTT Version V3.1.1. The payload can be defined by applications, that is, by the devices and IoT platform.

For details about MQTT syntax and APIs, see MQTT Version V3.1.1.

Common MQTT message types include CONNECT, SUBSCRIBE, and PUBLISH.

  • CONNECT: A client requests a connection to a server. For details about the parameters in the payload of a CONNECT message, see Device Connection Authentication.
  • SUBSCRIBE: A client subscribes to a topic. The main parameter Topic name in the payload of a SUBSCRIBE message indicates the topic whose subscriber is a device. For details, see Topics.
  • PUBLISH: The platform publishes a message.
    • The main parameter Topic name in the variable header indicates the release topic of the server or client. For details, see Topics.
    • The payload contains the data reported or commands delivered. It is a JSON object.

Constraints

  • An upstream topic is used by a device to send a request, report data, or return a response to the IoT platform.
  • A downstream topic is a command sent by the IoT platform to a device or a response sent by the IoT platform to a device.
  • After a device is connected to the IoT platform, the device needs to subscribe to downstream topics. Otherwise, the device cannot receive commands delivered or responses returned by the IoT platform. The calling of an API on the application side requires the cooperation of the device side. For example, if an application delivers a command, the device needs to subscribe to the downstream topic for command delivery. Otherwise, the device cannot receive commands from the platform, and the APIs for delivering commands will time out.