{"id":2518,"date":"2018-12-12T00:00:34","date_gmt":"2018-12-11T23:00:34","guid":{"rendered":"https:\/\/iot.fkainka.de\/?p=2518"},"modified":"2018-11-19T22:13:38","modified_gmt":"2018-11-19T21:13:38","slug":"day12-2018","status":"publish","type":"post","link":"https:\/\/iot.fkainka.de\/en\/day12-2018","title":{"rendered":"Day 12: MQTT Button"},"content":{"rendered":"<p>Today we will find again a button hidden behind the door of the Advent calendar. In our experiment\u00a0 today we will continue to cover the MQTT protocol, but this time in conjunction with Node-RED. We will also learn how two buttons can be evaluated simultaneously. The experiment today is structured as follows:<\/p>\n<div id=\"attachment_2519\" style=\"width: 446px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine.png\"><img aria-describedby=\"caption-attachment-2519\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-2519\" src=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine-827x1024.png\" alt=\"Der Aufbau mit zwei Buttons\" width=\"436\" height=\"539\" data-id=\"2519\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine-827x1024.png 827w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine-242x300.png 242w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine-768x951.png 768w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine.png 879w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/a><p id=\"caption-attachment-2519\" class=\"wp-caption-text\">Setup with two buttons<\/p><\/div>\n<p>So now we have two buttons that we can use. We activate the program for today. Then we import the Node-RED flow. You need to adapt it slightly by replacing <strong>[PID]<\/strong> in the topic with your personal MQTT ID. That\u2019s pretty easy if you use this trick:<\/p>\n<p>Copy the Node-RED flow into a text editor of your choice such as the Windows Editor for example. Select the <strong>Replace<\/strong> option (in Editor under <strong>Edit\/Replace<\/strong> ([Ctrl + H]). Enter <strong>[PID]<\/strong> into the <strong>Search for<\/strong> field and enter your personal ID in <strong>Replace with<\/strong>. Click <strong>Replace All<\/strong> and you have adjusted the flow and are now able to import and start it in Node-RED.\u00a0 But don\u2019t forget to disable previous flows.<\/p>\n<div id=\"attachment_2520\" style=\"width: 626px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12Ersetzen.png\"><img aria-describedby=\"caption-attachment-2520\" decoding=\"async\" loading=\"lazy\" class=\"size-large wp-image-2520\" src=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12Ersetzen-1024x445.png\" alt=\"So k\u00f6nnen Sie den Flow schnell auf Ihre pers\u00f6nliche ID anpassen\" width=\"616\" height=\"268\" data-id=\"2520\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12Ersetzen-1024x445.png 1024w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12Ersetzen-300x130.png 300w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12Ersetzen-768x333.png 768w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12Ersetzen-972x422.png 972w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12Ersetzen.png 1110w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><\/a><p id=\"caption-attachment-2520\" class=\"wp-caption-text\">Adjusting the flow using your personal ID is easy<\/p><\/div>\n<p><iframe style=\"border: none; width: 100%;\" src=\"https:\/\/pastebin.com\/embed_iframe\/eRdrHpEs\"><\/iframe><\/p>\n<p>In Node-RED go to the <strong>Debug <\/strong>tab and press a button on the breadboard. You will see the following message for example:<\/p>\n<div id=\"attachment_2523\" style=\"width: 385px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12_JSON.png\"><img aria-describedby=\"caption-attachment-2523\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-2523\" src=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12_JSON.png\" alt=\"\" width=\"375\" height=\"363\" data-id=\"2523\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12_JSON.png 503w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T12_JSON-300x290.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/a><p id=\"caption-attachment-2523\" class=\"wp-caption-text\">The JSON Message<\/p><\/div>\n<p>Key <strong>cmd<\/strong> will send the command <strong>get_button_state<\/strong>. Under <strong>value<\/strong> is an array with all buttons and their values. You can identify a button using <strong>pin_name<\/strong>, <strong>pin_id<\/strong> or <strong>pin_no<\/strong>. The first two values\u00a0 are already defined, the third indicates the used IO pin on the board. <strong>Pin_state<\/strong> indicates the button\u2019s Boolean value, which is TRUE or FALSE or HIGH or LOW. By the way, if the button is not pressed, the pin value is TRUE, because the pin is pulled to high by means of the internal pull-up resistor and by pressing a button it is pushed too low. The <strong>pin_value<\/strong> key indicates an analogue value which is not important for our buttons.<\/p>\n<p>I pressed Button2 here, and the board instantly sent a message with all enabled buttons and their values to the out topic that is affixed to the debug node and also to the topic<\/p>\n<p><strong>NodeESP\/[PID]\/button\/state\/get\/out<\/strong><\/p>\n<p>The latter topic is evaluated in Node-RED. Then there is a JSON node, which converts the plain text into a JSON object.\u00a0 Split node separates the button array into individual elements, which are passed on to the switch node one by one. This node checks the pin name and then determines which one of the two buttons that is. Template node then merely filters the value of the <strong>pin_state<\/strong> and sends TRUE or FALSE to the next node. This is a dashboard button that indicates a state, which is on, if the value was FALSE, and vice versa. Here it inverts the value of the button, so to speak.<\/p>\n<p>If you switch to the Dashboard, for example by clicking on the Dashboard tab on the right and then click the rectangle with the up arrow, you, too, can see the two buttons. When you release the button, the board immediately informs you about the status change and you can see straight away, which button is pressed and which button is not pressed.<\/p>\n<p>The huge advantage of MQTT and using an online broker is that you can assess the buttons from anywhere in the world. You could for example take the board with you to your job, while the Node-RED server is running on a machine at home. And then you could control the lights or the heating when you are on your way home, or you could use speech output to tell your folks at home that you are on your way. And all this you can do with a simple push of a button from anywhere in the world.<\/p>","protected":false},"excerpt":{"rendered":"<p>Today we will find again a button hidden behind the door of the Advent calendar. In our experiment\u00a0 today we will continue to cover the MQTT protocol, but this time in conjunction with Node-RED. We will also learn how two&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/iot.fkainka.de\/en\/day12-2018\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2519,"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":[315,312,313],"tags":[],"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 12: MQTT Button - 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\/day12-2018\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Day 12: MQTT Button - Internet of Things with the NanoESP\" \/>\n<meta property=\"og:description\" content=\"Today we will find again a button hidden behind the door of the Advent calendar. In our experiment\u00a0 today we will continue to cover the MQTT protocol, but this time in conjunction with Node-RED. We will also learn how two...Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/iot.fkainka.de\/day12-2018\" \/>\n<meta property=\"og:site_name\" content=\"Internet of Things with the NanoESP\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-11T23:00:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-19T21:13:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine.png\" \/>\n\t<meta property=\"og:image:width\" content=\"879\" \/>\n\t<meta property=\"og:image:height\" content=\"1089\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/iot.fkainka.de\/day12-2018\",\"url\":\"https:\/\/iot.fkainka.de\/day12-2018\",\"name\":\"Day 12: MQTT Button - Internet of Things with the NanoESP\",\"isPartOf\":{\"@id\":\"https:\/\/iot.fkainka.de\/#website\"},\"datePublished\":\"2018-12-11T23:00:34+00:00\",\"dateModified\":\"2018-11-19T21:13:38+00:00\",\"author\":{\"@id\":\"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a\"},\"breadcrumb\":{\"@id\":\"https:\/\/iot.fkainka.de\/day12-2018#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/iot.fkainka.de\/day12-2018\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/iot.fkainka.de\/day12-2018#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/iot.fkainka.de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tag 12: MQTT-Button\"}]},{\"@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 12: MQTT Button - 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\/day12-2018","og_locale":"en_US","og_type":"article","og_title":"Day 12: MQTT Button - Internet of Things with the NanoESP","og_description":"Today we will find again a button hidden behind the door of the Advent calendar. In our experiment\u00a0 today we will continue to cover the MQTT protocol, but this time in conjunction with Node-RED. We will also learn how two...Read more","og_url":"https:\/\/iot.fkainka.de\/day12-2018","og_site_name":"Internet of Things with the NanoESP","article_published_time":"2018-12-11T23:00:34+00:00","article_modified_time":"2018-11-19T21:13:38+00:00","og_image":[{"width":879,"height":1089,"url":"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/Day12_2Button_Steckplatine.png","type":"image\/png"}],"author":"fk","twitter_card":"summary_large_image","twitter_misc":{"Written by":"fk","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/iot.fkainka.de\/day12-2018","url":"https:\/\/iot.fkainka.de\/day12-2018","name":"Day 12: MQTT Button - Internet of Things with the NanoESP","isPartOf":{"@id":"https:\/\/iot.fkainka.de\/#website"},"datePublished":"2018-12-11T23:00:34+00:00","dateModified":"2018-11-19T21:13:38+00:00","author":{"@id":"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a"},"breadcrumb":{"@id":"https:\/\/iot.fkainka.de\/day12-2018#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/iot.fkainka.de\/day12-2018"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/iot.fkainka.de\/day12-2018#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/iot.fkainka.de\/"},{"@type":"ListItem","position":2,"name":"Tag 12: MQTT-Button"}]},{"@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\/2018\/11\/Day12_2Button_Steckplatine.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6McI0-EC","_links":{"self":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/2518"}],"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=2518"}],"version-history":[{"count":6,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/2518\/revisions"}],"predecessor-version":[{"id":2527,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/2518\/revisions\/2527"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/media\/2519"}],"wp:attachment":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/media?parent=2518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/categories?post=2518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/tags?post=2518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}