{"id":1455,"date":"2016-04-18T06:47:22","date_gmt":"2016-04-18T06:47:22","guid":{"rendered":"http:\/\/www.richa1.com\/RichardAlbritton\/?p=1455"},"modified":"2017-06-01T17:35:35","modified_gmt":"2017-06-01T17:35:35","slug":"app-inventor-and-particle","status":"publish","type":"post","link":"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/","title":{"rendered":"App Inventor and Particle"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-medium wp-image-1469 alignleft\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent09-300x255.png\" alt=\"AppInvent09\" width=\"300\" height=\"255\" srcset=\"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent09-300x255.png 300w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent09-768x654.png 768w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent09-1024x872.png 1024w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent09.png 1038w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/>This is set up to work with the <strong>WEB-Connected LED<\/strong> example app for the <strong>Particle Spark<\/strong>, <strong>Photon<\/strong>, or <strong>Electron<\/strong>.<!--more--><\/p>\n<p><strong>App Inventor<\/strong> is an easy way to make <strong>Apps<\/strong> for the <strong>Android<\/strong> platform. We will go through how to use <strong>App Inventor<\/strong> for communicating with any <strong>Particle<\/strong> device.<\/p>\n<p>&nbsp;<\/p>\n<h3>The Designer<br \/>\n<img loading=\"lazy\" class=\"size-full wp-image-1458 alignright\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent01-1.png\" alt=\"AppInvent01\" width=\"84\" height=\"55\" \/><\/h3>\n<p>You will want to make two buttons. The button names do not matter, but we will just call them <strong>ButtonOn<\/strong> and <strong>ButtonOff.<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-1457 alignright\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent02.png\" alt=\"AppInvent02\" width=\"63\" height=\"31\" \/>Next we will add the <strong>Web<\/strong> component with the following attributes.<\/p>\n<ol>\n<li>Check <strong>AllowCookies<\/strong>.<\/li>\n<li>Enter\u00a0<strong>https:\/\/api.particle.io\/v1\/devices\/<\/strong> in the <strong>Url<\/strong> field.<\/li>\n<\/ol>\n<h3>Code Blocks<\/h3>\n<p>Now we get into the codding. The thing to keep in mind is that a Particle function can only be called with an HTTP POST request. App Inventor makes it easy to send GET data so we will have to jump through a few hoops to get there.<\/p>\n<h4>Set Global Variables<\/h4>\n<p>First, lets set up some global variables. These can be found under Variables and initialize global. To this we will add a Text value to start with.<img loading=\"lazy\" class=\"wp-image-1462 size-full aligncenter\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent04-1.png\" alt=\"AppInvent04\" width=\"501\" height=\"232\" srcset=\"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent04-1.png 501w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent04-1-300x139.png 300w\" sizes=\"(max-width: 501px) 100vw, 501px\" \/><\/p>\n<ol>\n<li>Make sure the <strong>serverURL<\/strong> is set to &#8220;<strong>https:\/\/api.particle.io\/v1\/devices\/<\/strong>&#8220;.<\/li>\n<li>Copy the\u00a0<strong>Device ID<\/strong> and use that for the <strong>deviceID<\/strong> variable.<\/li>\n<li>Locate the\u00a0<strong>Access Token<\/strong> from your Particle account and use that for the <strong>accessToken<\/strong>.<\/li>\n<li><strong><br \/>\nFun<\/strong> should be set to the function name from the Particle code. For this instance, we are calling &#8220;led&#8221;.<\/li>\n<li><strong>Var<\/strong> is a placeholder for the value we will be sending to the function. It is blank.<\/li>\n<li><strong>HTTP_Reply<\/strong> can be used to get a conformation message from the Particle device.<\/li>\n<li><strong>PINstate<\/strong> can be used later to toggle the On\/Off button.<\/li>\n<\/ol>\n<h4>The Send Procedure<\/h4>\n<p>In App Inventor, a Procedure is a block of code that\u00a0can be called on to run at any time. This saves time and space when you need to run the same code over and over again.<\/p>\n<ol>\n<li><img loading=\"lazy\" class=\"size-full wp-image-1466 alignright\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent07.png\" alt=\"AppInvent07\" width=\"141\" height=\"69\" \/>From the <strong>Procedures<\/strong> blocks, add the <strong>Do<\/strong> block.<\/li>\n<li>Name this procedure &#8220;<strong>SendToParticle<\/strong>&#8220;.<\/li>\n<li>Add the <strong>Set Web1<\/strong> block from the <strong>Web1<\/strong> section to the new procedure.<\/li>\n<li>Now we will assemble a string for the\u00a0<strong>set Web1.Url<\/strong> by using the <strong>Join<\/strong> block from Text.<\/li>\n<li>All together we will be joining the <strong><span style=\"color: #339966;\">serverURL<\/span>, <span style=\"color: #3366ff;\">deviceID<\/span>,<\/strong> &#8220;<span style=\"color: #ff6600;\"><strong>\/<\/strong><\/span>&#8220;, <strong><span style=\"color: #ff00ff;\">Fun<\/span>,<\/strong> &#8220;<span style=\"color: #0000ff;\"><strong>?access_token=<\/strong><\/span>&#8220;, and <span style=\"color: #ff0000;\"><strong>accessToken<\/strong><\/span>.<\/li>\n<li>Under the <strong>Set.Url<\/strong> block, we will add a <strong>Call.PostText<\/strong> block from the <strong>Web1<\/strong> section.<\/li>\n<li>To this we will add a <strong>Join<\/strong> block for\u00a0sending to our Particle function via <strong>POST<\/strong> request.<\/li>\n<li>We will join &#8220;<strong>params=<\/strong>&#8221; and the <strong>Var<\/strong> value.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" class=\"wp-image-1465 size-full aligncenter\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent06.png\" alt=\"AppInvent06\" width=\"582\" height=\"281\" srcset=\"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent06.png 582w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent06-300x145.png 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/>When ever this\u00a0procedure is called Val will be sent via POST to:<\/p>\n<p style=\"padding-left: 30px;\"><strong><span style=\"color: #339966;\">https:\/\/api.particle.io\/v1\/devices\/<\/span><span style=\"color: #3366ff;\">your-device-id<\/span><span style=\"color: #ff6600;\">\/<\/span><span style=\"color: #ff00ff;\">led<\/span><span style=\"color: #0000ff;\">?access_token=<\/span><span style=\"color: #ff0000;\">your-access-token<\/span><\/strong><\/p>\n<h4>The Button Click<\/h4>\n<p>For now we will just use one button for ON and one for OFF. So we want to grab the <strong>when.click<\/strong> from the <strong>ButtonOn<\/strong> and <strong>ButtonOff<\/strong> blocks.<\/p>\n<ol>\n<li><img loading=\"lazy\" class=\"size-full wp-image-1464 alignright\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent05.png\" alt=\"AppInvent05\" width=\"271\" height=\"204\" \/>To that we will add a <strong>Set<\/strong> block for the <strong>Var<\/strong> variable. Also add the value of <strong>&#8220;on&#8221;<\/strong> to this.<\/li>\n<li>Next we will be calling on the <strong>SendToParticle<\/strong> Procedure.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>That is it!<\/p>\n<p>Once this App is loaded onto your phone it will turn the built-in LED, attached to Pin 7 on the Particle device, on or off.<\/p>\n<h4>What Next?<\/h4>\n<p>Well this is a good place to get you started. From here you can try to make the button toggle the LED on or off.<\/p>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-1467 aligncenter\" src=\"http:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent08-169x300.png\" alt=\"AppInvent08\" width=\"169\" height=\"300\" srcset=\"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent08-169x300.png 169w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent08-768x1365.png 768w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent08-576x1024.png 576w, https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent08.png 1080w\" sizes=\"(max-width: 169px) 100vw, 169px\" \/><\/p>\n<p>Change the button into an image to make things look a little nicer.<\/p>\n<p>Add a Relay to Pin 7 on the Particle device and you can turn an actual light on or off.<\/p>\n<p>The possibilities are nearly endless and this will help get you well on the road to making it easy to use the next big IOT&#8230; thing.<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/?share=email\" target=\"_blank\" title=\"Click to email this to a friend\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-1455\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-1455\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>This is set up to work with the WEB-Connected LED example app for the Particle Spark, Photon, or Electron.<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/?share=email\" target=\"_blank\" title=\"Click to email this to a friend\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-1455\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-1455\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/app-inventor-and-particle\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":1465,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[131,79],"tags":[72,132,105,133,71],"jetpack_featured_media_url":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2016\/04\/AppInvent06.png","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5AhH6-nt","_links":{"self":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/1455"}],"collection":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/comments?post=1455"}],"version-history":[{"count":5,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/1455\/revisions"}],"predecessor-version":[{"id":1799,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/1455\/revisions\/1799"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/media\/1465"}],"wp:attachment":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/media?parent=1455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/categories?post=1455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/tags?post=1455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}