{"id":285,"date":"2016-08-04T09:25:32","date_gmt":"2016-08-04T17:25:32","guid":{"rendered":"http:\/\/www.nathanbak.com\/?p=285"},"modified":"2026-01-02T20:04:41","modified_gmt":"2026-01-03T04:04:41","slug":"my-new-toy-part-4","status":"publish","type":"post","link":"https:\/\/nathanbak.com\/?p=285","title":{"rendered":"My New Toy (Part 4)"},"content":{"rendered":"<p>I finally got to the point where my new toy is able to <a href=\"http:\/\/www.nathanbak.com\/?p=274\">publish temperature information<\/a> to a database, so next is to make that information available on <a href=\"http:\/\/www.nathanbak.com\/?p=152\">BakBoard<\/a>.\u00a0 With the main pieces already deployed, the only thing necessary is to add the necessary connections.<\/p>\n<p>First I wrote a some JavaScript to poll the Webdis\/Redis server for the temperature.\u00a0 For extra credit I also have it contacting the <a href=\"http:\/\/services.faa.gov\/\">FAA Services REST API<\/a> to get information about weather at the Portland airport.\u00a0 Below is &#8220;temperature.js&#8221;.<\/p>\n<pre>function temperature() {\r\n\u00a0\u00a0 \u00a0setupTemperature();\r\n\u00a0\u00a0 \u00a0updateTemperature();\r\n\u00a0\u00a0 \u00a0window.setInterval(function(){ updateTemperature(); }, 100000);\r\n}\r\n\r\nfunction setupTemperature() {\r\n\u00a0\u00a0 \u00a0$('.temperature').html(\"&lt;div class='pdx'\/&gt;&lt;div class='upstairs'\/&gt;\");\r\n}\r\n\r\nfunction updateTemperature() {\r\n\u00a0\u00a0 \u00a0var myJson;\r\n\u00a0\u00a0 \u00a0var url = \"http:\/\/192.168.1.35:7379\/GET\/temperature\";\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0myJson = $.getJSON(url, function(obj) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0var f = parseFloat(obj.GET);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0var c = (f - 32) * 5 \/ 9;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$('.upstairs').html(\"Upstairs: \" + f.toFixed(1) + \"F (\" + c.toFixed(1) + \" C)\");\r\n\u00a0\u00a0 \u00a0});\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0url = \"http:\/\/services.faa.gov\/airport\/status\/PDX\";\r\n\u00a0\u00a0 \u00a0myJson = $.getJSON(url, function(obj) {\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0$('.pdx').html(\"Airport: \" + obj.weather.temp);\r\n\u00a0\u00a0 \u00a0});\r\n};<\/pre>\n<p>And here&#8217;s a very simple HTML file that uses the script above to display the airport and upstairs (where I put my new toy) temperatures:<\/p>\n<pre>&lt;html&gt;\r\n\u00a0\u00a0\u00a0 &lt;head&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;!-- I downloaded jQuery from http:\/\/code.jquery.com\/jquery-2.2.0.min.js--&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;script src=\"jquery-2.2.0.min.js\"&gt;&lt;\/script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>&lt;script src=\"temperature.js\"&gt;&lt;\/script&gt;<\/strong>\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;title&gt;Temperature&lt;\/title&gt;\r\n\u00a0\u00a0\u00a0 &lt;\/head&gt;\r\n\u00a0\u00a0\u00a0 &lt;body&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>&lt;div class=\"temperature\"&gt;&lt;\/div&gt;<\/strong> \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;script&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>temperature();<\/strong>\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/script&gt;\r\n\u00a0\u00a0\u00a0 &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>Viewing that script in a browser showed:<\/p>\n<pre>Airport: 73.0 F (22.8 C)\r\nUpstairs: 71.1F (21.7 C)<\/pre>\n<p>I basically added the bold HTML parts to the BakBoard .html file along with some css goodness and the temperature information is now displaying on BakBoard.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-290\" src=\"http:\/\/www.nathanbak.com\/wp-content\/uploads\/2016\/08\/bakboardTemp-1024x599.jpg\" alt=\"bakboardTemp\" width=\"840\" height=\"491\" srcset=\"https:\/\/nathanbak.com\/wp-content\/uploads\/2016\/08\/bakboardTemp-1024x599.jpg 1024w, https:\/\/nathanbak.com\/wp-content\/uploads\/2016\/08\/bakboardTemp-300x175.jpg 300w, https:\/\/nathanbak.com\/wp-content\/uploads\/2016\/08\/bakboardTemp-768x449.jpg 768w, https:\/\/nathanbak.com\/wp-content\/uploads\/2016\/08\/bakboardTemp-1200x702.jpg 1200w, https:\/\/nathanbak.com\/wp-content\/uploads\/2016\/08\/bakboardTemp.jpg 1387w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>I had fun playing with my new toy and learned a lot.\u00a0 The ESP8266 seems to have a lot of potential and I want to try more things.\u00a0 Of course now that I have my only module in use, I may have to get another one for play . . .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I finally got to the point where my new toy is able to publish temperature information to a database, so next is to make that information available on BakBoard.\u00a0 With the main pieces already deployed, the only thing necessary is to add the necessary connections. First I wrote a some JavaScript to poll the Webdis\/Redis &hellip; <a href=\"https:\/\/nathanbak.com\/?p=285\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;My New Toy (Part 4)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5,13,10],"class_list":["post-285","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bakboard","tag-esp8266","tag-making"],"_links":{"self":[{"href":"https:\/\/nathanbak.com\/index.php?rest_route=\/wp\/v2\/posts\/285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nathanbak.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nathanbak.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nathanbak.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nathanbak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=285"}],"version-history":[{"count":6,"href":"https:\/\/nathanbak.com\/index.php?rest_route=\/wp\/v2\/posts\/285\/revisions"}],"predecessor-version":[{"id":292,"href":"https:\/\/nathanbak.com\/index.php?rest_route=\/wp\/v2\/posts\/285\/revisions\/292"}],"wp:attachment":[{"href":"https:\/\/nathanbak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nathanbak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nathanbak.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}