Development Approach
After the device is successfully connected to the private deployment Broker, you can use an MQTT client tool to log in to the Broker with an administrator account and password, send messages to the topic of the specified device, and the device will respond to the commands.
The development approach is to connect to MQTT through programming to send and receive upstream and downstream messages of the device.
MQTT Libraries
The following is a collection of libraries for connecting to MQTT and processing messages in different programming languages.
Please select a suitable library based on the language of the application for programming and development.
| Programming Language | Available Libraries |
|---|---|
| C | Eclipse Paho C: A general-purpose MQTT C library suitable for multiple platforms. MQTT-C: A small, easy-to-understand and use MQTT v3.1.1 protocol client library, especially suitable for resource-constrained environments. |
| C++ | Eclipse Paho C++: A general-purpose MQTT C++ library that provides synchronous and asynchronous APIs. libmosquittopp: A C++ library for the Mosquitto MQTT Broker. |
| Python | Eclipse Paho Python: A popular Python MQTT client library, originally developed from the Mosquitto Python client. gmqtt: An asynchronous Python 3 MQTT client library. |
| Java | Eclipse Paho Java: A general-purpose MQTT Java library that supports multiple features such as will messages and SSL/TLS. HiveMQ MQTT Client: A high-performance Java MQTT client library that supports MQTT 5.0 and MQTT 3.1.1. |
| Go | Eclipse Paho Go: A general-purpose MQTT Go library suitable for Go language environments. |
| JavaScript/Node.js | MQTT.js: A JavaScript MQTT library suitable for Node.js environments. Ascoltatori: A Node.js publish/subscribe library that supports Redis, AMQP, MQTT, and ZeroMQ. |
| Other Languages | .NET/dotNET: Libraries such as HiveMQtt and MQTTnet provide multiple MQTT client libraries for the .NET platform. Languages including Dart, Erlang, Elixir, Haskell, Lua, OCaml, Perl, PHP, Prolog, Qt, Ruby, Rust, Shell Script, Smalltalk, Swift, and Tcl: All these languages have their own MQTT libraries or tools to support MQTT communication. |
Appendix: Device-Related Topics
| Function | Topic Type | Device Permission |
|---|---|---|
| Device Topic | thing/{product_key}/{device_name}/# | Subscribe |
| Command Delivery | thing/{product_key}/{device_name}/order/server | Read-Only |
| Command Delivery Acknowledgment | thing/{product_key}/{device_name}/order/client | Publish |
| Event Reporting Acknowledgment | thing/{product_key}/{device_name}/event/server | Read-Only |
| Event Reporting | thing/{product_key}/{device_name}/event/client | Publish |
| Status Reporting Acknowledgment | thing/{product_key}/{device_name}/state/server | Read-Only |
| Status Reporting | thing/{product_key}/{device_name}/state/client | Publish |
| Configuration Delivery | thing/{product_key}/{device_name}/config/server | Read-Only |
| Configuration Delivery Acknowledgment | thing/{product_key}/{device_name}/config/client | Publish |
| Firmware Upgrade Information | thing/{product_key}/{device_name}/ota/server | Read-Only |
| Firmware Upgrade Reporting | thing/{product_key}/{device_name}/ota/client | Publish |
After logging in, the device will subscribe to the general topic immediately:
thing/{product_key}/{device_name}/#
The device has publish permission for all topics ending with client; The cloud has publish permission for all topics ending with server
Message Format: Both sent and received messages are JSON strings, e.g.: {"mid": "Message ID", "data": "Data Content", "ts": "Timestamp"}
1. Message ID: A 16-character string composed of numbers and letters. Specified by the original publisher of the message. If it is an acknowledgment (reply) message, it must be the mid of the original message. The mid is generated randomly and must be unique.
2. Data Content: Can be a key-value object or an array of key-value objects. The specific content is related to the topic and functional attributes.
3. Timestamp: The time when the message is published (NTP time), accurate to at least seconds, and can be accurate to milliseconds.