Skip to content

About MQTT

MQTT is a client-server transport protocol that uses the publish/subscribe pattern. It is lightweight and has features that allow it to be used effectively in an environment with limited throughput and/or high latency.

Clients can, among others:

  • Subscribe topics - they request the server to send them messages incoming on the chosen topics.
  • Unsubscribe topic - they request the server to no longer send them messages from chosen topics.
  • Publish messages - send a message on chosen topic to server, which then sends out a message to all clients that have subscribed the topic..

Topics

Topics have hierachical structure, so one topic can have its dependants (sub-topics). Thanks to that it's possible to organize messages in groups, where each group can have it's own sub-groups and so on. Levels in topics are divided with /, and each level is string of characters, eg. A/B has two levels A and sublevel B. It is important for subscriptions, which with help of special characters can span over multiple topics.

These special characters are:

+
it covers one level and must be the only character on this level. As a result, topics that have a different character combinations in place of + will contain in a subscription with special character. In other words it means so much that in place of + you can insert any value. For example: topics like a/b/c/d, a/b/e/d matches subscription a/b/+/d but topics a/b/c or a/b/c/d/e do not.
#
it covers multiple levels but must be the last character in whole subscription topic. This sign will match any other characters or even multiple levels, eg. topic subscription a/# matches a/b, a/b/c, but not b/c.

Both special signs (+ and #) can be used together in one topic subscription, eg. a/+/c/# which matches a/b/c/d, a/d/c/f.

Our server

As a MQTT server we use Mosquitto (more about it here). It listens on few ports:

  • 1883 - without encryption, requires authentication
  • 8883 - with SSL, requires authentication
  • 9001 - WebSockets without encryption, requires authentication
  • 9002 - WebSockets with SSL, requires authentication

More

You can find more detailed information about MQTT protocol at: