{"id":2455,"date":"2018-12-04T00:00:42","date_gmt":"2018-12-03T23:00:42","guid":{"rendered":"https:\/\/iot.fkainka.de\/?p=2455"},"modified":"2018-11-19T16:20:43","modified_gmt":"2018-11-19T15:20:43","slug":"day4-2018","status":"publish","type":"post","link":"https:\/\/iot.fkainka.de\/en\/day4-2018","title":{"rendered":"Day 4: UDP and JSON"},"content":{"rendered":"<p>Behind the fourth door of the Advent calendar is a set of cables that is very useful for the upcoming hardware setup. But today in our project we are going to look at the JSON format; what is it and how does it help us communicating with the board.<\/p>\n<p>As usual, first you need to activate today\u2019s program. You will also need the Packet Sender program with the same settings that we were using yesterday. Today, a message appears only after you briefly press on the board\u2019s boot button. This message looks like this:<\/p>\n<p style=\"text-align: center;\"><strong>{&#8220;cmd&#8221;:&#8221;boot_pressed&#8221;}<\/strong><\/p>\n<div id=\"attachment_2456\" style=\"width: 525px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender.png\"><img aria-describedby=\"caption-attachment-2456\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-2456\" src=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender.png\" alt=\"Die Nachricht im Packet-Sender-Programm\" width=\"515\" height=\"418\" data-id=\"2456\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender.png 946w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender-300x244.png 300w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender-768x623.png 768w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/a><p id=\"caption-attachment-2456\" class=\"wp-caption-text\">The message in Packet Sender<\/p><\/div>\n<p>This is a JSON (<strong>JavaScript Object Notation<\/strong>) message. JSON is a slim data exchange format for machines that is also very readable for humans. Basically, everything in the JSON format consists of names and values. First, we have the name of the value (which is also called key), in our case this is <strong>cmd<\/strong> (short for command), and then the value itself, here <strong>boot_pressed<\/strong>. Both texts are separated by a colon and, because this is text, it is also enclosed in quotation marks. A complete JSON object is also surrounded by curly brackets.<\/p>\n<p>The board not only sends messages, it can also receive messages. To make this happen, you need to fix a few settings in the Packet Sender program. In the upper part there is a text field labelled <strong>Address<\/strong>. Here again you need to enter the broadcast address which is also used by the board. Alternatively, enter the board IP or just the mDNS name (simply <strong>nodeesp<\/strong>). In the <strong>Port<\/strong> field on the right, enter again the port <strong>55056<\/strong>. Last but not least, select <strong>UDP <\/strong>from the drop-down menu further on the right. Now you can enter a message into the field <strong>ASCII<\/strong> located a little higher up and <strong>Send<\/strong> it. Start with sending a trial text such as <strong>Hello<\/strong>. Since the Packet Sender listens on the same port and you are also using the broadcast IP address, you will also receive some of the messages sent. In addition, you will receive the message <strong>{&#8220;cmd&#8221;:&#8221;ack&#8221;}<\/strong> from the board.<strong>\u00a0 <\/strong>ack is the short of <strong>acknowledged<\/strong>. The board thus has confirmed the receipt of a message, although most likely it couldn\u2019t do anything with the message itself.<\/p>\n<div id=\"attachment_2457\" style=\"width: 688px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender2.png\"><img aria-describedby=\"caption-attachment-2457\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-2457\" src=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender2.png\" alt=\"So senden Sie einen Text an das Board\" width=\"678\" height=\"180\" data-id=\"2457\" srcset=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender2.png 942w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender2-300x80.png 300w, https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender2-768x204.png 768w\" sizes=\"(max-width: 678px) 100vw, 678px\" \/><\/a><p id=\"caption-attachment-2457\" class=\"wp-caption-text\">sending a text<\/p><\/div>\n<p>If you send a predefined command in JSON, things will look a bit different. If you send the text\u00a0<strong>{&#8220;cmd&#8221;:&#8221;ping&#8221;},<\/strong> for example, you will get <strong>{&#8220;cmd&#8221;: &#8220;pong&#8221;}<\/strong> as a reply from the board after a short while. You could also try other commands. For example, <strong>{&#8220;cmd&#8221;: &#8220;get_wifi_status&#8221;}<\/strong> will return the connection status of the board. <strong>{&#8220;cmd&#8221;: &#8220;get_wifi_scan&#8221;}<\/strong> will detect and list all Wi-Fi networks in range.<\/p>\n<p>You can find a couple of universal commands on the board page or on the project page. But be careful: there are a few commands in the category <strong>Settings<\/strong> that will make changes to the settings of the board and then nothing will work anymore. If this happens, go to the default settings by holding down the boot button for more than 10 seconds. You can use this method for all programs that have WPS in brackets after the program name. You have the same function on the configuration page under <strong>Advanced Settings <\/strong>and then (<strong>Restore Default Configuration<\/strong>).<\/p>\n<p>As a third option move pin 13 to LOW during the startup of the board. Don\u2019t forget to disconnect pin 13 after the reset.<\/p>\n<p>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Behind the fourth door of the Advent calendar is a set of cables that is very useful for the upcoming hardware setup. But today in our project we are going to look at the JSON format; what is it and&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/iot.fkainka.de\/en\/day4-2018\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2456,"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 4: UDP and JSON - 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\/en\/day4-2018\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Day 4: UDP and JSON - Internet of Things with the NanoESP\" \/>\n<meta property=\"og:description\" content=\"Behind the fourth door of the Advent calendar is a set of cables that is very useful for the upcoming hardware setup. But today in our project we are going to look at the JSON format; what is it and...Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/iot.fkainka.de\/en\/day4-2018\" \/>\n<meta property=\"og:site_name\" content=\"Internet of Things with the NanoESP\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-03T23:00:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-19T15:20:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender.png\" \/>\n\t<meta property=\"og:image:width\" content=\"946\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/iot.fkainka.de\/en\/day4-2018\",\"url\":\"https:\/\/iot.fkainka.de\/en\/day4-2018\",\"name\":\"Day 4: UDP and JSON - Internet of Things with the NanoESP\",\"isPartOf\":{\"@id\":\"https:\/\/iot.fkainka.de\/#website\"},\"datePublished\":\"2018-12-03T23:00:42+00:00\",\"dateModified\":\"2018-11-19T15:20:43+00:00\",\"author\":{\"@id\":\"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a\"},\"breadcrumb\":{\"@id\":\"https:\/\/iot.fkainka.de\/en\/day4-2018#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/iot.fkainka.de\/en\/day4-2018\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/iot.fkainka.de\/en\/day4-2018#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/iot.fkainka.de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Day 4: UDP and JSON\"}]},{\"@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 4: UDP and JSON - 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\/en\/day4-2018","og_locale":"en_US","og_type":"article","og_title":"Day 4: UDP and JSON - Internet of Things with the NanoESP","og_description":"Behind the fourth door of the Advent calendar is a set of cables that is very useful for the upcoming hardware setup. But today in our project we are going to look at the JSON format; what is it and...Read more","og_url":"https:\/\/iot.fkainka.de\/en\/day4-2018","og_site_name":"Internet of Things with the NanoESP","article_published_time":"2018-12-03T23:00:42+00:00","article_modified_time":"2018-11-19T15:20:43+00:00","og_image":[{"width":946,"height":768,"url":"https:\/\/iot.fkainka.de\/wp-content\/uploads\/2018\/11\/T4PacketSender.png","type":"image\/png"}],"author":"fk","twitter_card":"summary_large_image","twitter_misc":{"Written by":"fk","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/iot.fkainka.de\/en\/day4-2018","url":"https:\/\/iot.fkainka.de\/en\/day4-2018","name":"Day 4: UDP and JSON - Internet of Things with the NanoESP","isPartOf":{"@id":"https:\/\/iot.fkainka.de\/#website"},"datePublished":"2018-12-03T23:00:42+00:00","dateModified":"2018-11-19T15:20:43+00:00","author":{"@id":"https:\/\/iot.fkainka.de\/#\/schema\/person\/d3205fdf2649027fc35e240d4f8b285a"},"breadcrumb":{"@id":"https:\/\/iot.fkainka.de\/en\/day4-2018#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/iot.fkainka.de\/en\/day4-2018"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/iot.fkainka.de\/en\/day4-2018#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/iot.fkainka.de\/"},{"@type":"ListItem","position":2,"name":"Day 4: UDP and JSON"}]},{"@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\/T4PacketSender.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6McI0-DB","_links":{"self":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/2455"}],"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=2455"}],"version-history":[{"count":3,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/2455\/revisions"}],"predecessor-version":[{"id":2462,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/posts\/2455\/revisions\/2462"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/media\/2456"}],"wp:attachment":[{"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/media?parent=2455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/categories?post=2455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iot.fkainka.de\/en\/wp-json\/wp\/v2\/tags?post=2455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}