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:

Here are some tips how to name topics properly.

Topics are case-sensitive. Be careful with that because kitchen/temperature and Kitchen/Temperatureare two different topics

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.

Avoid using spaces in a topic because it makes harder to read and debug topics if something goes wrong.

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.

Avoid uncommon characters. Try to use only ASCII characters because they are displayed correctly.

Remember about extendibility. It should be easy to add new sensors or IoT devices to your topic hierarchy without changing the whole topic tree.

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