MQTT support

MQTT is the most low-level functionality that mDash provides for the device management. While the whole product could be built purely on top of the raw MQTT, please take a look at device shadow and RPC functionality before jumping on MQTT.

The most common case for using MQTT is saving messages (like logs or metrics) to the built-in database.

MQTT Publish

In order to publish a message, use mDashPublish function:

void mDashPublish(const char *topic, const char *fmt, ...);

The fmt argument is a format string that supports the same specifiers as mDashReturnSuccess function. Example usage:

mDashPublish("my/test", "{%Q: %d}", "value", 123);

The above call sends message {"value": 123} to the topic my/test.

MQTT Subscribe

In order to subscribe to the topic and receive message, please use mDashSubscribe. The callback function fn will be called when a message is sent to a subscribed topic:

void mDashSubscribe(const char *topic, void (*fn)(const char *, const char *));


static void onmessage(const char *topic, const char *message) {
  printf("Topic: [%s], message: [%s]\n", topic, message);

mDashSubscribe("my/test", onmessage);