{"id":519,"date":"2016-01-27T05:29:00","date_gmt":"2016-01-27T05:29:00","guid":{"rendered":"https:\/\/www.thebillplease.io\/play\/?p=519"},"modified":"2022-01-19T19:02:00","modified_gmt":"2022-01-19T19:02:00","slug":"almost-xmas-lights-2016","status":"publish","type":"post","link":"https:\/\/www.thebillplease.io\/play\/2016\/01\/27\/almost-xmas-lights-2016\/","title":{"rendered":"Almost Xmas Ornaments 2016"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1728\" src=\"https:\/\/www.thebillplease.io\/play\/wp-content\/uploads\/2022\/01\/IMG_9905-1024x673-1-1024x673-1.jpg\" alt=\"\" width=\"1024\" height=\"673\" srcset=\"https:\/\/www.thebillplease.io\/play\/wp-content\/uploads\/2022\/01\/IMG_9905-1024x673-1-1024x673-1.jpg 1024w, https:\/\/www.thebillplease.io\/play\/wp-content\/uploads\/2022\/01\/IMG_9905-1024x673-1-1024x673-1-300x197.jpg 300w, https:\/\/www.thebillplease.io\/play\/wp-content\/uploads\/2022\/01\/IMG_9905-1024x673-1-1024x673-1-768x505.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>I didn&#8217;t have time to complete this project &#8211; so, I didn&#8217;t&nbsp;launch it &#8211; but, I&#8217;m posting my progress here so that I can leverage it in the future.<\/p>\n<p>The idea was to let users light up different xmas ornaments on our tree and send us comments through the Facebook comment plugin.<\/p>\n<p>I had already used the Facebook comment plugin to LED panel a few years back and had done the internet connected relay. This time, I wanted to build on those projects to&nbsp;solve for multiple users actioning the lights and make it wireless. I was polling before, which turned out to be unreliable. To solve for this problem, I looked into using some form of websocket&nbsp;&#8211; MQTT.<\/p>\n<p>I found the MQTT.js library, which connected rather seamlessly to&nbsp;adafruit.io.<\/p>\n<p>I put together a website with&nbsp;three buttons and was able to get them to pass through their statuses via the protocol. Interestingly, the library doesn&#8217;t really support subscribing to multiple topics, so I had to leverage delimiters to determine which button was on or off. I used &#8216;0&#8217; for off and &#8216;1&#8217; for on which resulted in the following payload&nbsp;&#8220;0|1|0&#8221;.<\/p>\n<p>I still need to have the ESP8266 subscribe to the topic I created &#8211; but that should be relatively straightforward. I&#8217;ll then leverage C to split on a delimiter <a href=\"http:\/\/arduino.stackexchange.com\/questions\/1013\/how-do-i-split-an-incoming-string\" target=\"_blank\" rel=\"noopener\">Eg article<\/a>&nbsp;and should have a nice &#8220;tadah&#8221; moment. One of the things to note for MQTT is that you have to keep it alive, &#8220;You must send something to the MQTT broker once every MQTT_CONN_KEEPALIVE seconds<\/p>\n<p>You can set it in <strong>Adafruit_MQTT.h<\/strong> &#8211; the default is 300 seconds (5 minutes)<\/p>\n<p><strong>If you are not publishing data, only subscribing, you must send a ping to let the broker know you&#8217;re around!<\/strong><\/p>\n<p>Pinging is easy, just call <strong>ping<\/strong>()&#8221;<\/p>\n<p>Here is the <a href=\"http:\/\/thebillplease.net\/mqtt\/mqtt\/final.html\" target=\"_blank\" rel=\"noopener\">WIP for the web portion of the project<\/a>.<\/p>\n<p>Here is a link to the project with<a href=\"http:\/\/thebillplease.net\/mqtt\/mqtt\/test5.html\" target=\"_blank\" rel=\"noopener\"> simple buttons.<\/a><\/p>\n<p>Tutorials used<\/p>\n<ul>\n<li><a href=\"https:\/\/learn.adafruit.com\/mqtt-adafruit-io-and-you\/arduino-plus-library-setup\" target=\"_blank\" rel=\"noopener\">Adafruit<\/a>&nbsp;w\/MQTT<\/li>\n<li><a href=\"https:\/\/learn.adafruit.com\/adafruit-feather-huzzah-esp8266\" target=\"_blank\" rel=\"noopener\">Adafruit ESP8266 setup<\/a><\/li>\n<li><a href=\"https:\/\/learn.adafruit.com\/mqtt-adafruit-io-and-you\/intro-to-adafruit-mqtt\" target=\"_blank\" rel=\"noopener\">Adafruit.io setup<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I didn&#8217;t have time to complete this project &#8211; so, I didn&#8217;t&nbsp;launch it &#8211; but, I&#8217;m posting my progress here so that I can leverage it in the future. The idea was to let&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":1743,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,9],"tags":[],"class_list":["post-519","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-internet-of-things","category-wireless-control"],"_links":{"self":[{"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/posts\/519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/comments?post=519"}],"version-history":[{"count":4,"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/posts\/519\/revisions"}],"predecessor-version":[{"id":1891,"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/posts\/519\/revisions\/1891"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/media\/1743"}],"wp:attachment":[{"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/media?parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/categories?post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thebillplease.io\/play\/wp-json\/wp\/v2\/tags?post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}