User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
tut:mqtt [2018-07-20 10:09]
jk [What is MQTT]
tut:mqtt [2018-07-20 18:27]
jk
Line 4: Line 4:
  
 ... see [[https://​www.hivemq.com/​blog/​mqtt-essentials-part-1-introducing-mqtt]] ... see [[https://​www.hivemq.com/​blog/​mqtt-essentials-part-1-introducing-mqtt]]
 +
 +... see [[https://​blog.doubleslash.de/​mqtt-fuer-dummies/​]]
 ===== MQTT Data Flow by Examples ===== ===== MQTT Data Flow by Examples =====
  
Line 10: Line 12:
 Based on this image the following examples can show typical data flows Based on this image the following examples can show typical data flows
  
-==== Example: 1 Publisher, no Subscriber ​====+==== Example: 1 Publisher, no Subscriper ​====
  
   * Client X connected   * Client X connected
Line 16: Line 18:
 {{ :​tut:​mqtt:​mqtt1.svg?​600x0 }} {{ :​tut:​mqtt:​mqtt1.svg?​600x0 }}
  
-If Client X publishes any data with Topic 1 and nobody is listening (nobody has subscribed ​Topic 1) the data is lost.+If Client X publishes any data with Topic 1 and nobody is listening (nobody has subscriped ​Topic 1) the data is lost.
  
 (Exception: see Topics with Retain Flag) (Exception: see Topics with Retain Flag)
  
-==== Example: 1 Publisher, 1 Subscriber ​====+==== Example: 1 Publisher, 1 Subscriper ​====
  
   * Client A connected   * Client A connected
-  * Client B connected and subscribes ​Topic 2+  * Client B connected and subscripes ​Topic 2
  
 {{ :​tut:​mqtt:​mqtt2.svg?​600x0 |}} {{ :​tut:​mqtt:​mqtt2.svg?​600x0 |}}
Line 29: Line 31:
 If Client A publishes any data with Topic 2 and Client B is notified instantly about change of Topic 2. If Client A publishes any data with Topic 2 and Client B is notified instantly about change of Topic 2.
  
-==== Example: Many Publisher, Many Subscriber ​====+==== Example: Many Publisher, Many Subscriper ​====
  
   * Client A, C, E connected   * Client A, C, E connected
-  * Client B connected and subscribes ​Topic 2 +  * Client B connected and subscripes ​Topic 2 
-  * Client F connected and subscribes ​Topic 3+  * Client F connected and subscripes ​Topic 3
  
 {{ :​tut:​mqtt:​mqtt3.svg?​600x0 }} {{ :​tut:​mqtt:​mqtt3.svg?​600x0 }}
Line 39: Line 41:
 Any Client can publish any data with any Topic at anytime. The subscriping Clients are notified instantly about change of the Topics they subscripes and only that. Any Client can publish any data with any Topic at anytime. The subscriping Clients are notified instantly about change of the Topics they subscripes and only that.
  
-==== Example: Many Publisher, 1 Subscriber ​with Wildcard ====+==== Example: Many Publisher, 1 Subscriper ​with Wildcard ====
  
   * Client A, C, E connected   * Client A, C, E connected
-  * Client D connected and subscribes ​Topic with '#'​+  * Client D connected and subscripes ​Topic with '#'​
  
 {{ :​tut:​mqtt:​mqtt4.svg?​600x0 }} {{ :​tut:​mqtt:​mqtt4.svg?​600x0 }}
Line 50: Line 52:
 ==== Example: Request and Answer ==== ==== Example: Request and Answer ====
  
-  * Client E connected and subscribes ​Topic 4 +  * Client E connected and subscripes ​Topic 4 
-  * Client F connected and subscribes ​Topic 3+  * Client F connected and subscripes ​Topic 3
  
 {{ :​tut:​mqtt:​mqtt5.svg?​600x0 }} {{ :​tut:​mqtt:​mqtt5.svg?​600x0 }}
Line 62: Line 64:
  
   * Client G connected   * Client G connected
-  * Client H connected and subscribes ​Topic 5 with QoS+  * Client H connected and subscripes ​Topic 5 with QoS
  
 {{ :​tut:​mqtt:​mqtt6.svg?​600x0 }} {{ :​tut:​mqtt:​mqtt6.svg?​600x0 }}
Line 80: Line 82:
  
   * Client Y was connected long time ago   * Client Y was connected long time ago
-  * Client Z connects now and subscribes ​Topic 6+  * Client Z connects now and subscripes ​Topic 6
  
 {{ :​tut:​mqtt:​mqtt7.svg?​600x0 }} {{ :​tut:​mqtt:​mqtt7.svg?​600x0 }}
Line 91: Line 93:
 |0|fire and forget| |0|fire and forget|
 |1|saved on broker| |1|saved on broker|
 +
 +===== Topic Wording =====
 +
 +There is no law that you have to name your topics in a special way. So the following names are (principle) correct:
 +
 +  * /​MyHome/​Kitchen/​Temperature
 +  * /​MYHOME/​KITCHEN/​TEMPERATURE
 +  * MyHome/​Kitchen/​Temperature
 +  * MyHome.Kitchen.Temperature
 +  * MyHomeKitchenTemperature
 +  * MHKT
 +  * /​Temperature/​Kitchen/​MyHome
 +  * 42
 +
 +But there are some guidelines for names that all clinets can filter and handle subscriptions in an easy way:
 +
 +  * The topic begins with a '/'​
 +  * The topic do NOT end with a '/'​
 +  * A '/'​ seperates topic levels
 +  * The topic levels starts with the most commen level
 +
 +So the recommented name is:
 +
 +  * /​MyHome/​Kitchen/​Temperature
 +
 +===== Subscription Wildcard Examples =====
 +
 +==== Exact Match ====
 +
 +On subscriping **"/​MyHome/​Kitchen/​Temperature"​** you get:
 +  * **/​MyHome/​Kitchen/​Temperature**
 +  * <​del>/​MyHome/​Kitchen/​Humity</​del>​
 +  * <​del>/​MyHome/​Kitchen/​Fridge/​Temperature</​del>​
 +  * <​del>/​MyHome/​Livingroom/​Temperature</​del>​
 +  * <​del>/​MyHome/​Livingroom/​Humity</​del>​
 +  * <​del>/​MyGarden/​Air/​Temperature</​del>​
 +  * <​del>/​MyGarden/​Pool/​Temperature</​del>​
 +
 +==== # Wildcard ====
 +
 +On subscriping **"/#"​** you get:
 +  * /​MyHome/​Kitchen/​Temperature
 +  * /​MyHome/​Kitchen/​Humity
 +  * /​MyHome/​Kitchen/​Fridge/​Temperature
 +  * /​MyHome/​Livingroom/​Temperature
 +  * /​MyHome/​Livingroom/​Humity
 +  * /​MyGarden/​Air/​Temperature
 +  * /​MyGarden/​Pool/​Temperature
 +
 +On subscriping **"/​MyHome/#"​** you get:
 +  * **/​MyHome/​**Kitchen/​Temperature
 +  * **/​MyHome/​**Kitchen/​Humity
 +  * **/​MyHome/​**Kitchen/​Fridge/​Temperature
 +  * **/​MyHome/​**Livingroom/​Temperature
 +  * **/​MyHome/​**Livingroom/​Humity
 +  * <​del>/​MyGarden/​Air/​Temperature</​del>​
 +  * <​del>/​MyGarden/​Pool/​Temperature</​del>​
 +
 +On subscriping **"/​MyHome/​Kitchen/#"​** you get:
 +  * **/​MyHome/​Kitchen/​**Temperature
 +  * **/​MyHome/​Kitchen/​**Humity
 +  * **/​MyHome/​Kitchen/​**Fridge/​Temperature
 +  * <​del>/​MyHome/​Livingroom/​Temperature</​del>​
 +  * <​del>/​MyHome/​Livingroom/​Humity</​del>​
 +  * <​del>/​MyGarden/​Air/​Temperature</​del>​
 +  * <​del>/​MyGarden/​Pool/​Temperature</​del>​
 +
 +==== + Wildcard ====
 +
 +On subscriping **"/​MyHome/​+/​Temperature"​** you get:
 +  * **/​MyHome/​**Kitchen**/​Temperature**
 +  * <​del>/​MyHome/​Kitchen/​Humity</​del>​
 +  * <​del>/​MyHome/​Kitchen/​Fridge/​Temperature</​del>​
 +  * **/​MyHome/​**Livingroom**/​Temperature**
 +  * <​del>/​MyHome/​Livingroom/​Humity</​del>​
 +  * <​del>/​MyGarden/​Air/​Temperature</​del>​
 +  * <​del>/​MyGarden/​Pool/​Temperature</​del>​
 +
 +On subscriping **"/​+/​+/​Temperature"​** you get:
 +  * /​MyHome/​Kitchen**/​Temperature**
 +  * <​del>/​MyHome/​Kitchen/​Humity</​del>​
 +  * <​del>/​MyHome/​Kitchen/​Fridge/​Temperature</​del>​
 +  * /​MyHome/​Livingroom**/​Temperature**
 +  * <​del>/​MyHome/​Livingroom/​Humity</​del>​
 +  * /​MyGarden/​Air**/​Temperature**
 +  * /​MyGarden/​Pool**/​Temperature**
 +
 +On subscriping **"/​+/​+/​+/​Temperature"​** you get:
 +  * <​del>/​MyHome/​Kitchen/​Temperature</​del>​
 +  * <​del>/​MyHome/​Kitchen/​Humity</​del>​
 +  * /​MyHome/​Kitchen/​Fridge**/​Temperature**
 +  * <​del>/​MyHome/​Livingroom/​Temperature</​del>​
 +  * <​del>/​MyHome/​Livingroom/​Humity</​del>​
 +  * <​del>/​MyGarden/​Air/​Temperature</​del>​
 +  * <​del>/​MyGarden/​Pool/​Temperature</​del>​
 +
 +
  
  
  

ezPiC

Easy *Pi Controller for IoT Devices