{"id":33,"date":"2015-09-28T08:44:39","date_gmt":"2015-09-28T08:44:39","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=33"},"modified":"2016-09-11T15:21:29","modified_gmt":"2016-09-11T15:21:29","slug":"controlling-cloudbit-using-raspberry-pi-2","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2015\/09\/28\/controlling-cloudbit-using-raspberry-pi-2\/","title":{"rendered":"Controlling cloudBit using Raspberry Pi 2"},"content":{"rendered":"<p>I have had Raspberry Pi for two years now and badly wanted to get the newer Raspberry Pi 2. I finally got it last week and decided to tinker with it during my spare time.<\/p>\n<p>Setting it up was pretty straightforward. Just connected the power source, keyboard, mouse, HDMI monitor, and wifi dongle, and the system booted normally.<\/p>\n<figure id=\"attachment_34\" aria-describedby=\"caption-attachment-34\" style=\"width: 351px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573.jpg\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"34\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2015\/09\/28\/controlling-cloudbit-using-raspberry-pi-2\/img_1573\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573.jpg\" data-orig-size=\"2448,3264\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.4&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 4S&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1443436797&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.28&quot;,&quot;iso&quot;:&quot;320&quot;,&quot;shutter_speed&quot;:&quot;0.05&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;1&quot;}\" data-image-title=\"Raspberry Pi 2\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Connecting Raspberry Pi 2&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573-768x1024.jpg\" class=\" wp-image-34\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573-225x300.jpg?resize=351%2C468\" alt=\"Connecting Raspberry Pi 2\" width=\"351\" height=\"468\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573.jpg?resize=225%2C300&amp;ssl=1 225w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573.jpg?resize=768%2C1024&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573.jpg?w=1560&amp;ssl=1 1560w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1573.jpg?w=2340&amp;ssl=1 2340w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/a><figcaption id=\"caption-attachment-34\" class=\"wp-caption-text\">Connecting Raspberry Pi 2<\/figcaption><\/figure>\n<p>When I was looking for\u00a0a simple experiment, it occurred to me that I could try and control my littleBits <a href=\"http:\/\/littlebits.cc\/cloud\" target=\"_blank\">cloudBit<\/a>\u00a0module using Raspi.<\/p>\n<p>So this is what I did. I put together a very simple cloudBit project: <em><strong>Power -&gt; Push button -&gt; cloudBit -&gt; Number Display <\/strong><\/em><\/p>\n<figure id=\"attachment_35\" aria-describedby=\"caption-attachment-35\" style=\"width: 473px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572.jpg\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"35\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2015\/09\/28\/controlling-cloudbit-using-raspberry-pi-2\/img_1572\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572-e1443420509753.jpg\" data-orig-size=\"3264,2448\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.4&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 4S&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1443385384&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.28&quot;,&quot;iso&quot;:&quot;160&quot;,&quot;shutter_speed&quot;:&quot;0.05&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;6&quot;}\" data-image-title=\"cloudBit\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;cloudBit Setup&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572-e1443420509753-1024x768.jpg\" class=\"wp-image-35 \" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572-e1443420509753-300x225.jpg?resize=473%2C355\" alt=\"cloudBit Setup\" width=\"473\" height=\"355\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572-e1443420509753.jpg?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572-e1443420509753.jpg?resize=1024%2C768&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572-e1443420509753.jpg?w=1560&amp;ssl=1 1560w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2015\/09\/IMG_1572-e1443420509753.jpg?w=2340&amp;ssl=1 2340w\" sizes=\"(max-width: 473px) 100vw, 473px\" \/><\/a><figcaption id=\"caption-attachment-35\" class=\"wp-caption-text\">cloudBit Setup<\/figcaption><\/figure>\n<p>I made sure that my cloudBit setup was connected to the same wifi network as the Raspberry Pi.<\/p>\n<p>The good news is that cloudBit can be controlled through <a href=\"http:\/\/developers.littlebitscloud.cc\" target=\"_blank\">HTTP requests<\/a>, so any programming environment that supports this can be used. Since I am a huge fan of Mathematica and since there is a version of Mathematica that comes as part of Raspian bundle, I decided to write a simple program in Mathematica to interact with the cloudBit module.<\/p>\n<p>I wrote two functions, one to read the status of the cloudBit and the other to control the output (Number Display) of cloudBit. The functions are given below (I have masked the cloudBit authentication key):<\/p>\n<p><strong><em>CloudBitFetch[] :=\u00a0<\/em><\/strong><strong><em>ImportString[<\/em><\/strong><\/p>\n<p><strong><em>URLFetch[&#8220;https:\/\/api-http.littlebitscloud.cc\/devices\/00e04c0383a1&#8221;,<\/em><\/strong><\/p>\n<p><strong><em>&#8220;Headers&#8221; -&gt; {&#8220;Authorization&#8221; -&gt;\u00a0<\/em><\/strong><strong><em>&#8220;Bearer &lt;key&gt;\u201c, <\/em><\/strong><\/p>\n<p><strong><em>&#8220;Accept&#8221; -&gt; &#8220;application\/vnd.littlebits.v2+json&#8221;}], &#8220;JSON&#8221;]<\/em><\/strong><\/p>\n<p>The above function uses the GET method to read the status of the device and returns the results as a JSON object. My device ID is hardcoded for convenience.<\/p>\n<p><em><strong>CloudBitSend[value_, durn_] :=\u00a0<\/strong><\/em><\/p>\n<p><em><strong>URLFetch[&#8220;https:\/\/api-http.littlebitscloud.cc\/devices\/00e04c0383a1\/<\/strong><\/em><em><strong>output&#8221;, &#8220;Method&#8221; -&gt; &#8220;Post&#8221;,\u00a0<\/strong><\/em><em><strong>&#8220;Headers&#8221; -&gt; {&#8220;Authorization&#8221; -&gt;\u00a0<\/strong><\/em><em><strong>&#8220;Bearer &lt;Key&gt;&#8221;, <\/strong><\/em><em><strong>&#8220;Accept&#8221; -&gt; &#8220;application\/vnd.littlebits.v2+json&#8221;},\u00a0<\/strong><\/em><em><strong>&#8220;Parameters&#8221; -&gt; { &#8220;percent&#8221; -&gt; ToString[value],\u00a0<\/strong><\/em><em><strong>&#8220;duration_ms&#8221; -&gt; ToString[durn]}]<\/strong><\/em><\/p>\n<p>This function takes a value (0 to 99) and duration in millis and sends them to the output of cloudBit (using Post method). This causes the Number Display to display the value for the specified duration.<\/p>\n<p>Here is how we can use these functions (result from Mathematica is shown below each call):<\/p>\n<p><strong>In[2] = devicedata = CloudBitFetch[]<\/strong><\/p>\n<p><em>Out[2] = {label -&gt; RangaCloudBit, user_id -&gt; 49762,\u00a0<\/em><\/p>\n<p><em>\u00a0input_interval_ms -&gt; 750, id -&gt; 00e04c0383a1,\u00a0<\/em><\/p>\n<p><em>\u00a0ap -&gt; {ssid -&gt; mmsindia, strength -&gt; 100,\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0 mac -&gt; 48:EE:0C:CF:E6:99, server_id -&gt; 4kR9rW-kx,\u00a0<\/em><\/p>\n<p><em>\u00a0\u00a0 socket_id -&gt; NyQkwnZ1g, status -&gt; 2},\u00a0<\/em><\/p>\n<p><em>\u00a0is_connected -&gt; True, subscriptions&#8221;-&gt; {}, subscribers -&gt; {}}<\/em><\/p>\n<p><strong>In[3]:= &#8220;label&#8221; \/. devicedata<\/strong><\/p>\n<p><em>Out[3]= RangaCloudBit<\/em><\/p>\n<p><strong>In[4]:= CloudBitSend[30, 4000]<\/strong><\/p>\n<p><em>Out[4]= {&#8220;success&#8221;:true}<\/em><\/p>\n<p>If you observe carefully, you can see that the display reads &#8220;31&#8221; whereas the value I sent was &#8220;30&#8221;. I can&#8217;t understand why! Whatever value I send, the display reads one more than that value. This may require further investigation, which I will probably take up later.<\/p>\n<p>One of the other popular experiments with cloudBit involves setting up IFTTT so that interactions\/notifications between cloudBit and IFTTT-enabled channels can take place. In my case, I created two recipes in IFTTT, one to send me an email via gmail when the Push button at the input of cloudBit is pressed, and the other to send me an SMS when the Push button is pressed. Both these worked as expected!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have had Raspberry Pi for two years now and badly wanted to get the newer Raspberry Pi 2. I finally got it last week and decided to tinker with it during my spare time. Setting it up was pretty straightforward. Just connected the power source, keyboard, mouse, HDMI monitor, and wifi dongle, and the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[14,13,72],"tags":[10,11,12],"class_list":["post-33","post","type-post","status-publish","format-standard","hentry","category-electronics","category-internet-of-things-iot","category-mathematica","tag-cloudbits","tag-littlebits","tag-raspberry-pi"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-x","jetpack-related-posts":[{"id":285,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/07\/22\/using-julia-to-interact-with-mathematica\/","url_meta":{"origin":33,"position":0},"title":"Using Julia to Interact with Mathematica","author":"admin","date":"July 22, 2016","format":false,"excerpt":"Mathematica is a powerful environment for symbolic and numerical computation. I have been using it for many years now. In this post\u00a0I had explained how we can use Mathematica bundled with Raspberry distribution to control littleBits devices. When I saw that there is support in Julia for interacting with Mathematica,\u2026","rel":"","context":"In &quot;Julia&quot;","block_context":{"text":"Julia","link":"https:\/\/www.rangakrish.com\/index.php\/category\/julia\/"},"img":{"alt_text":"Julia Session","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/07\/Julia-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/07\/Julia-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/07\/Julia-1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":912,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/04\/22\/question-answering-using-dependency-trees\/","url_meta":{"origin":33,"position":1},"title":"Question Answering\u00a0Using Dependency Trees","author":"admin","date":"April 22, 2018","format":false,"excerpt":"A few weeks ago I had written about my brief experiment with Mathematica's new feature, which provides answers to questions based on given text. After that post, I spent some time thinking about how to implement something similar. In today's post, I want to show you what I have been\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Dependency Tree","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/04\/Deptree-example.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1285,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/09\/parsing-text-with-meaningclouds-text-analytics-api\/","url_meta":{"origin":33,"position":2},"title":"Parsing Text with MeaningCloud&#8217;s Text Analytics API","author":"admin","date":"December 9, 2018","format":false,"excerpt":"There is wide-spread interest in Natural Language Processing (NLP) today, and there are several API services available to cater to this demand. See this article for a fairly detailed list of services. All of them support multiple languages, including English. Today, I am going to share my experience in working\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Get Words Function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/12\/Get-words.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/12\/Get-words.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/12\/Get-words.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1025,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/08\/19\/sicstus-prolog-building-a-windows-executable\/","url_meta":{"origin":33,"position":3},"title":"Sicstus Prolog &#8211; Building a Windows Executable","author":"admin","date":"August 19, 2018","format":false,"excerpt":"In my previous post, I showed how to build a C-based Windows DLL to execute Prolog predicates in the Sicstus Prolog\u00a0engine. Today, I want to show how to build an executable (on Windows) from a C\/C++ program that uses Sicstus prolog engine. The process is quite simple. In order to\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Creating WordNet Prolog Image","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=525%2C300 1.5x"},"classes":[]},{"id":4012,"url":"https:\/\/www.rangakrish.com\/index.php\/2026\/01\/01\/common-lisp-metaobject-protocol-classes-are-just-objects\/","url_meta":{"origin":33,"position":4},"title":"Common Lisp Metaobject Protocol: Classes are Just Objects!","author":"admin","date":"January 1, 2026","format":false,"excerpt":"In today\u2019s popular languages such as C++, Java, Golang, Rust, Python, etc., classes are fixed constructs defined by the language. They have a definite syntax that can\u2019t be changed while programming. We are all used to this of course. But what makes Common Lisp stand out is that in that\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"A Simple Class","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/01\/code1-300x42.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1770,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/11\/10\/calling-c-methods-from-sicstus-prolog-through-com-interface\/","url_meta":{"origin":33,"position":5},"title":"Calling C# Methods from Sicstus Prolog through COM Interface","author":"admin","date":"November 10, 2019","format":false,"excerpt":"Recently\u00a0I needed to make use of a C# library (which I had implemented a few years ago) from Sicstus Prolog. Calling C\/C++ functions from Sicstus Prolog is fairly well documented. When it comes to C#\/.NET, the official documentation recommends the PrologBeans library. After going through the documentation, I felt that\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Prolog Client Code","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}