{"id":1398,"date":"2016-12-20T00:01:05","date_gmt":"2016-12-19T23:01:05","guid":{"rendered":"http:\/\/iot.fkainka.de\/?p=1398"},"modified":"2018-10-24T16:05:10","modified_gmt":"2018-10-24T15:05:10","slug":"day-20-mqtt-message-queue-telemetry-transport","status":"publish","type":"post","link":"https:\/\/iot.fkainka.de\/en\/day-20-mqtt-message-queue-telemetry-transport","title":{"rendered":"Day 20: MQTT (Message Queue Telemetry Transport)"},"content":{"rendered":"<p>For the last days of this Advent, you&#8217;ll now become familiar with a subject that plays a large role in the realm of the IoT. We&#8217;re dealing with the messaging protocol MQTT, which was specially developed for the communication from machine to machine (M2M). The protocol is thus so brilliant because e.g. control data, measurement data or texts can be exchanged very easily and compactly. The overhead (data that&#8217;s transferred alongside the actual user data) is much lower than with HTTP and can be processed readily even by embedded devices, meaning microcontrollers like our NanoESP. At the same time, the controller doesn&#8217;t constantly have to establish a connection and query whether there&#8217;s been a change; instead, the connection is continually maintained and the client automatically gives information about changes.<\/p>\n<p>A so-called broker forms the basis for the communication. A broker is a server application that processes all data. A device can now connect to the broker and &#8220;publish&#8221; messages, i.e. send them to the broker. Another device can &#8220;subscribe&#8221; to specific topics and then immediately receives a new message published to this topic delivered by the broker. So that you don&#8217;t have to set up your own broker, a public broker has been set up for you at the address <strong>broker.fkainka.de<\/strong>.<\/p>\n<div id=\"attachment_1399\" style=\"width: 626px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1.jpg\"><img aria-describedby=\"caption-attachment-1399\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-1399 size-large\" src=\"http:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-1024x679.jpg\" alt=\"Der MQTT Broker stellt die Nachrichten zu\" width=\"616\" height=\"408\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-1024x679.jpg 1024w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-300x199.jpg 300w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-768x509.jpg 768w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-320x213.jpg 320w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-972x645.jpg 972w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-196x131.jpg 196w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1-153x102.jpg 153w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1.jpg 1556w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><\/a><p id=\"caption-attachment-1399\" class=\"wp-caption-text\">The MQTT broker delivers the messages<\/p><\/div>\n<p>The topics are structured hierarchically, where subtopics are each separated with a slash. There are also so-called wild cards. With a &#8220;+&#8221; or &#8220;#&#8221; you can subscribe to multiple topics at the same time. Publishing with the wild cards &#8220;#&#8221; or &#8220;+&#8221; isn&#8217;t possible, however. For example, the topics<\/p>\n<p><strong>MyHome\/Kitchen\/Temperature<\/strong><\/p>\n<p><strong>MyHome\/Bathroom\/Temperature<\/strong><\/p>\n<p>can thus be received at the same time by subscribing to the topic<\/p>\n<p><strong>MyHome\/+\/Temperature<\/strong><\/p>\n<p>&#8211; The plus thereby always replaces only one topic level. The # replaces all at once. With the topic<\/p>\n<p><strong>MyHome\/#<\/strong><\/p>\n<p>you thus receive all messages that are published in all subtopics of MyHome. The data that are published to a topic can be virtually anything, from pure texts to measurement values or simple 1\/0 commands for switching a light.<br \/>\n<iframe loading=\"lazy\" style=\"height: 400px; width: 100%; margin: 10px 0;\" src=\"https:\/\/create.arduino.cc\/editor\/FKainka\/ae0063ba-4121-471e-bdcf-1f990d9ab433\/preview?embed\" width=\"300\" height=\"150\" frameborder=\"0\"><\/iframe><br \/>\nBehind today&#8217;s door is a button. In the test, we primarily want to make a couple of dry runs on the subject of MQTT. So load today&#8217;s programme to the board and open the serial monitor. After a short time, you&#8217;ll see more or less the following messages:<\/p>\n<div id=\"attachment_1400\" style=\"width: 372px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_2_SeMo.jpg\"><img aria-describedby=\"caption-attachment-1400\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-1400\" src=\"http:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_2_SeMo.jpg\" alt=\"Die Meldungen im Seriellen Monitor\" width=\"362\" height=\"326\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_2_SeMo.jpg 481w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_2_SeMo-300x270.jpg 300w\" sizes=\"(max-width: 362px) 100vw, 362px\" \/><\/a><p id=\"caption-attachment-1400\" class=\"wp-caption-text\">The messages on the serial monitor<\/p><\/div>\n<p>The board has thus connected first to the WLAN and then to the online broker. So that the many different users don&#8217;t fall into the queue, a special structure must be maintained. You can therefore write only in subtopics of the form <strong>NanoESP\/MyMQTTiD\/&#8230;<\/strong> , where you have to replace <strong>MyMQTTiD<\/strong> with the ID that you receive from the board, displayed on the serial monitor. For today, that means that everything is written to the individually adapted topic <strong>NanoESP\/MyMQTTiD\/test.<\/strong><\/p>\n<p>So that you can also see what you&#8217;re writing in a topic, we use an online tool from the company HiveMQ on the computer. With this tool, you can likewise connect to the broker and subscribe to your personal topics or write to them. Now go to the page www.hivemq.com\/try-out\/ and click there on \u201cTry the websocket client\u201d. Now you first have to establish a connection to the broker by entering the address <strong>broker.fkainka.de<\/strong> in the menu option &#8220;Connection&#8221; under &#8220;Host.&#8221; The port and the ClientID can remain the same, and the other parameters are also correct. Click &#8220;Connect.&#8221; If everything worked, the text &#8220;connected&#8221; appears next to a green dot at the top right and you have the option in other areas to publish in a topic or to subscribe to a topic.<\/p>\n<p>First click on \u201cAdd New Topic Subscription\u201d and enter <strong>NanoESP\/MyMQTTiD\/test<\/strong> in the topic field, where you replace MyMQTTiD with the ID from the serial monitor. Now reset the NanoESP by pressing the Reset button on the board. After a short time, you should receive the message \u201cHello from my NanoESP\u201d in the browser under the &#8220;Messages&#8221; item. You can also send a message to the board by going into the topic field <strong>NanoESP\/MyMQTTiD\/test<\/strong> under &#8220;Publish&#8221; and entering any message you choose, like \u201cHello from my Browser,\u201d under &#8220;Message&#8221;. Now you receive the message displayed on the serial monitor. So the communication is up.<\/p>\n<p><div id=\"attachment_1401\" style=\"width: 932px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_3_Website.jpg\"><img aria-describedby=\"caption-attachment-1401\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-1401 size-full\" src=\"http:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_3_Website.jpg\" alt=\"The Websocket Client\" width=\"922\" height=\"660\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_3_Website.jpg 922w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_3_Website-300x215.jpg 300w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_3_Website-768x550.jpg 768w\" sizes=\"(max-width: 922px) 100vw, 922px\" \/><\/a><p id=\"caption-attachment-1401\" class=\"wp-caption-text\">The Websocket Client<\/p><\/div><\/p>","protected":false},"excerpt":{"rendered":"<p>For the last days of this Advent, you&#8217;ll now become familiar with a subject that plays a large role in the realm of the IoT. We&#8217;re dealing with the messaging protocol MQTT, which was specially developed for the communication from&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/iot.fkainka.de\/en\/day-20-mqtt-message-queue-telemetry-transport\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":1399,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[123,124,311],"tags":[130],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Day 20: MQTT (Message Queue Telemetry Transport) - Internet of Things with the NanoESP<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Day 20: MQTT (Message Queue Telemetry Transport) - Internet of Things with the NanoESP\" \/>\n<meta property=\"og:description\" content=\"For the last days of this Advent, you&#8217;ll now become familiar with a subject that plays a large role in the realm of the IoT. We&#8217;re dealing with the messaging protocol MQTT, which was specially developed for the communication from...Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport\" \/>\n<meta property=\"og:site_name\" content=\"Internet of Things with the NanoESP\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-19T23:01:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-10-24T15:05:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1556\" \/>\n\t<meta property=\"og:image:height\" content=\"1032\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"fk\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"fk\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport\",\"url\":\"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport\",\"name\":\"Day 20: MQTT (Message Queue Telemetry Transport) - Internet of Things with the NanoESP\",\"isPartOf\":{\"@id\":\"https:\/\/iot.fkainka.de\/#website\"},\"datePublished\":\"2016-12-19T23:01:05+00:00\",\"dateModified\":\"2018-10-24T15:05:10+00:00\",\"author\":{\"@id\":\"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a\"},\"breadcrumb\":{\"@id\":\"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/iot.fkainka.de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tag 20: MQTT (Message Queue Telemetry Transport)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/iot.fkainka.de\/#website\",\"url\":\"https:\/\/iot.fkainka.de\/\",\"name\":\"Internet of Things with the NanoESP\",\"description\":\"The webpage for the Arduino compatible WiFi-Board\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/iot.fkainka.de\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a\",\"name\":\"fk\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/iot.fkainka.de\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/141cf958a831e66efabf9674e117e8d9?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/141cf958a831e66efabf9674e117e8d9?s=96&d=identicon&r=g\",\"caption\":\"fk\"},\"url\":\"https:\/\/iot.fkainka.de\/en\/author\/fk\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Day 20: MQTT (Message Queue Telemetry Transport) - Internet of Things with the NanoESP","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport","og_locale":"en_US","og_type":"article","og_title":"Day 20: MQTT (Message Queue Telemetry Transport) - Internet of Things with the NanoESP","og_description":"For the last days of this Advent, you&#8217;ll now become familiar with a subject that plays a large role in the realm of the IoT. We&#8217;re dealing with the messaging protocol MQTT, which was specially developed for the communication from...Read more","og_url":"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport","og_site_name":"Internet of Things with the NanoESP","article_published_time":"2016-12-19T23:01:05+00:00","article_modified_time":"2018-10-24T15:05:10+00:00","og_image":[{"width":1556,"height":1032,"url":"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1.jpg","type":"image\/jpeg"}],"author":"fk","twitter_card":"summary_large_image","twitter_misc":{"Written by":"fk","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport","url":"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport","name":"Day 20: MQTT (Message Queue Telemetry Transport) - Internet of Things with the NanoESP","isPartOf":{"@id":"https:\/\/iot.fkainka.de\/#website"},"datePublished":"2016-12-19T23:01:05+00:00","dateModified":"2018-10-24T15:05:10+00:00","author":{"@id":"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a"},"breadcrumb":{"@id":"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/iot.fkainka.de\/day-20-mqtt-message-queue-telemetry-transport#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/iot.fkainka.de\/"},{"@type":"ListItem","position":2,"name":"Tag 20: MQTT (Message Queue Telemetry Transport)"}]},{"@type":"WebSite","@id":"https:\/\/iot.fkainka.de\/#website","url":"https:\/\/iot.fkainka.de\/","name":"Internet of Things with the NanoESP","description":"The webpage for the Arduino compatible WiFi-Board","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/iot.fkainka.de\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a","name":"fk","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/iot.fkainka.de\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/141cf958a831e66efabf9674e117e8d9?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/141cf958a831e66efabf9674e117e8d9?s=96&d=identicon&r=g","caption":"fk"},"url":"https:\/\/iot.fkainka.de\/en\/author\/fk"}]}},"jetpack_featured_media_url":"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2016\/09\/Day20_1.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6McI0-my","_links":{"self":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/1398"}],"collection":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/comments?post=1398"}],"version-history":[{"count":4,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/1398\/revisions"}],"predecessor-version":[{"id":1534,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/1398\/revisions\/1534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/media\/1399"}],"wp:attachment":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/media?parent=1398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/categories?post=1398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/tags?post=1398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}