{"id":23321,"date":"2019-05-03T03:19:54","date_gmt":"2019-05-03T10:19:54","guid":{"rendered":"https:\/\/m2msupport.net\/m2msupport\/?page_id=23321"},"modified":"2019-06-02T12:00:43","modified_gmt":"2019-06-02T19:00:43","slug":"mqtt-topics","status":"publish","type":"page","link":"https:\/\/m2msupport.net\/m2msupport\/mqtt-topics\/","title":{"rendered":"MQTT Topics"},"content":{"rendered":"<p>MQTT clients publish their contents using MQTT topics which are strings that is used by MQTT broker to filter the messages from MQTT clients.<\/p>\n<h3><strong>MQTT Topic Levels<\/strong><\/h3>\n<p>MQTT Topics can have one or more levels and the levels are separated by forward slash. Topics are case-sensitive. Examples of MQTT topics are,<\/p>\n<ul>\n<li>office\/groundfloor\/room1\/temperature<\/li>\n<li>factory\/device1\/motorspeed<\/li>\n<\/ul>\n<h3><strong>Related Topics<\/strong><\/h3>\n<ul>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/how-mqtt-works\/\">How MQTT works?<\/a><\/li>\n<li>MQTT \u2013 Connect to Broker\n<ul>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-connect-to-eclipse-public-mqtt-server\/\">Connect to Eclipse public MQTT Server<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-connect-to-mosquitto-broker-on-local-windows-machine\/\">Connect to Mosquitto MQTT server on local Windows machine<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-topics\/\">MQTT Topics<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-publish\/\">MQTT Publish<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-subscriber\/\">MQTT Subscribe<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-quality-of-service-qos\/\">MQTT Quality of Service (QoS)<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-keep-alive-pingreq-pingresp\/\">MQTT \u2013 Keep Alive with PINGREQ and PINGRESP<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/install-mqtt-broker-mosquitto-in-windows\/\">Install MQTT broker Mosquitto in Windows<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-user-authentication\/\">Mosquitto Broker \u2013 Enable user authentication<\/a><\/li>\n<li><a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-user-name-and-password-authentication-to-mqtt-broker-connection\/\">MQTT Broker connection with user name and password<\/a><\/li>\n<\/ul>\n<h3><strong>MQTT Topic Wildcards<\/strong><\/h3>\n<p>Clients can subscribe to MQTT topics using wildcards which cane be single-level or multi-level. Wildcards can only be used for subscribing to topics, not for publishing topics.<\/p>\n<p><strong>Single-level Wildcard<\/strong>: &#8216;+&#8217; symbol is used to subscribe for single-level wildcards.<\/p>\n<p>Example of single-level wildcard topic,<\/p>\n<p>office\/groundfloor\/+\/temperature<\/p>\n<p>When clients subscribe to above topics with single-level topics, they will subscribe messages for below topics<\/p>\n<p>office\/groundfloor\/room1\/temperature<\/p>\n<p>office\/groundfloor\/room2\/temperature<\/p>\n<p>office\/groundfloor\/room3\/temperature<\/p>\n<p><strong>Multi-level Wildcard<\/strong>: &#8216;#&#8217; symbol is used to subscribe for multi-level wildcards. They can be used only at the end of topics.<\/p>\n<p>Example if multi-level wildcard topic,<\/p>\n<p>office\/groundfloor\/room1\/#<\/p>\n<p>When clients subscribe to above topic with multi-level wildcard, they will receive&nbsp; all messages pubslished under offoce\/groundfloor\/room1<\/p>\n<p>office\/groundfloor\/room1\/temperature<\/p>\n<p>office\/groundfloor\/room1\/humidity<\/p>\n<p>office\/groundfloor\/room1\/noise<\/p>\n<p>Try the <a href=\"https:\/\/m2msupport.net\/m2msupport\/download-at-command-tester\/\">AT Command Tester<\/a> tool to create new topics and publish messages,<\/p>\n<p><a href=\"https:\/\/m2msupport.net\/m2msupport\/wp-content\/uploads\/2019\/05\/mqtt_topics.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23328\" src=\"https:\/\/m2msupport.net\/m2msupport\/wp-content\/uploads\/2019\/05\/mqtt_topics.png\" alt=\"\" width=\"1102\" height=\"789\" srcset=\"https:\/\/m2msupport.net\/m2msupport\/wp-content\/uploads\/2019\/05\/mqtt_topics.png 1102w, https:\/\/m2msupport.net\/m2msupport\/wp-content\/uploads\/2019\/05\/mqtt_topics-300x215.png 300w, https:\/\/m2msupport.net\/m2msupport\/wp-content\/uploads\/2019\/05\/mqtt_topics-768x550.png 768w, https:\/\/m2msupport.net\/m2msupport\/wp-content\/uploads\/2019\/05\/mqtt_topics-1024x733.png 1024w, https:\/\/m2msupport.net\/m2msupport\/wp-content\/uploads\/2019\/05\/mqtt_topics-600x430.png 600w\" sizes=\"auto, (max-width: 1102px) 100vw, 1102px\" \/><\/a><\/p>\n<h3><strong>MQTT Server logs with examples of subscribing to topics<\/strong><\/h3>\n<p><code><\/code><\/p>\n<p><code><\/code><\/p>\n<p><code><\/code><code><\/code><\/p>\n<p>C:\\Program Files\\mosquitto&gt;mosquitto -v<br \/>1556880402: mosquitto version 1.6.0 starting<br \/>1556880402: Using default config.<br \/>1556880402: Opening ipv6 listen socket on port 1883.<br \/>1556880402: Opening ipv4 listen socket on port 1883.<br \/>1556880410: New connection from 127.0.0.1 on port 1883.<br \/>1556880410: New client connected from 127.0.0.1 as at_tester_2305 (p2, c1, k60).<br \/>1556880410: No will message specified.<br \/>1556880410: Sending CONNACK to at_tester_2305 (0, 0)<br \/>1556880424: Received SUBSCRIBE from at_tester_2305<br \/>1556880424: SensorReadings (QoS 1)<br \/>1556880424: at_tester_2305 1 SensorReadings<br \/>1556880424: Sending SUBACK to at_tester_2305<br \/>1556880429: Received UNSUBSCRIBE from at_tester_2305<br \/>1556880429: SensorReadings<br \/>1556880429: at_tester_2305 SensorReadings<br \/>1556880429: Sending UNSUBACK to at_tester_2305<br \/>1556880462: Received SUBSCRIBE from at_tester_2305<br \/>1556880462: office\/groundfloor\/+\/temperature (QoS 1)<br \/>1556880462: at_tester_2305 1 office\/groundfloor\/+\/temperature<br \/>1556880462: Sending SUBACK to at_tester_2305<br \/>1556880490: Received SUBSCRIBE from at_tester_2305<br \/>1556880490: office\/groundfloor\/room1\/# (QoS 1)<br \/>1556880490: at_tester_2305 1 office\/groundfloor\/room1\/#<br \/>1556880490: Sending SUBACK to at_tester_2305<br \/>1556880550: Received PINGREQ from at_tester_2305<br \/>1556880550: Sending PINGRESP to at_tester_2305<\/p>\n<p><code><br \/>\n<\/code><\/p>\n<p><code><\/code><\/p>\n<p><code><\/code><\/p>\n<p><\/p>\n<div class=\"video-responsive\"><iframe loading=\"lazy\" id=\"youTubePlayer\" src=\"https:\/\/www.youtube.com\/embed\/RcfRSX4nmac\" width=\"750\" height=\"421\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MQTT clients publish their contents using MQTT topics which are strings that is used by MQTT broker to filter the messages from MQTT clients. MQTT Topic Levels MQTT Topics can have one or more levels and the levels are separated &hellip; <a href=\"https:\/\/m2msupport.net\/m2msupport\/mqtt-topics\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"software_howto.php","meta":{"footnotes":""},"class_list":["post-23321","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/pages\/23321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/comments?post=23321"}],"version-history":[{"count":12,"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/pages\/23321\/revisions"}],"predecessor-version":[{"id":26659,"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/pages\/23321\/revisions\/26659"}],"wp:attachment":[{"href":"https:\/\/m2msupport.net\/m2msupport\/wp-json\/wp\/v2\/media?parent=23321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}