How to use MQTT: advices from the expert

Last week we released MQTT Buddy, a new MQTT client on Android. It’s a simple and lightweight (only 1.7 Mb) mobile app which is very easy to use.

Our client is based on MQTT Protocol that uses publish/subscribe pattern. That means that you subscribe to different topics where other clients publish their messages.  All the messages are going through MQTT Broker. General scheme of MQTT communication:

mqtt architecture

Here are some tips how to name topics properly.

  1. Topics are case-sensitive. Be careful with that because kitchen/temperature and Kitchen/Temperature are two different topics
  2. Do not start your topic with a forward slash: /home/kitchen/temperature. In this case you create an extra topic level with a zero character at the front.
  3. Avoid using spaces in a topic because it makes harder to read and debug topics if something goes wrong.
  4. Try to create short topics. For small devices it’s important to save the size of sending information. Topics are always included in every message it’s used in.
  5. Avoid uncommon characters. Try to use only ASCII characters because they are displayed correctly.
  6. Remember about extendibility. It should be easy to add new sensors or IoT devices to your topic hierarchy without changing the whole topic tree.
  7. Be specific. Use detailed topics name. For instance, when you have two sensors in a kitchen, create two different topics: home/kitchen/temperature and home/kitchen/motion instead of sending all messages to home/kitchen

If you have some tips from your own experience share it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *