forked from quadrosnatwit/skillsacademy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISS-Node-RED-Flow.json
1 lines (1 loc) · 20.5 KB
/
ISS-Node-RED-Flow.json
1
[{"id":"486f3bb0.f64324","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"2113eb92.1e2cc4","type":"watson-conversation-v1","z":"486f3bb0.f64324","name":"ISS Assistant","workspaceid":"","multiuser":false,"context":true,"empty-payload":false,"default-endpoint":true,"service-endpoint":"https://gateway.watsonplatform.net/assistant/api","timeout":"","optout-learning":false,"x":470,"y":80,"wires":[["92a5a533.40a368"]],"inputLabels":["msg.payload"]},{"id":"92a5a533.40a368","type":"function","z":"486f3bb0.f64324","name":"Generate Timestamp","func":"msg.assistant = msg.payload\nif (msg.payload.intents.length > 0 || msg.payload.entities.length >0){\n msg.payload = (new Date()).getTime()\n}\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":80,"wires":[["68b93215.de04ec"]]},{"id":"c211f29b.793c4","type":"http in","z":"486f3bb0.f64324","name":"","url":"/botchat","method":"post","upload":false,"swaggerDoc":"","x":100,"y":80,"wires":[["8cf8273a.46fbe8"]]},{"id":"8cf8273a.46fbe8","type":"function","z":"486f3bb0.f64324","name":"process chat input","func":"// stash away incoming data\nmsg.mydata = {};\nmsg.mydata.messagein = msg.req.body.msgdata;\nmsg.payload = msg.mydata.messagein;\n\nmsg.params = { \"context\": msg.req.body.context};\n\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":80,"wires":[["2113eb92.1e2cc4"]]},{"id":"8de58684.0ec738","type":"function","z":"486f3bb0.f64324","name":"Assistant output to Chat","func":"\ncurrent_payload = msg.payload;\nmsg.payload = {};\nif (current_payload && current_payload.hasOwnProperty('display_name')){\n // geocoding response\n msg.payload.message = \"Currently Location: \" + current_payload.display_name;\n msg.payload.lat = current_payload.lat;\n msg.payload.lon = current_payload.lon;\n} else if (current_payload.hasOwnProperty('error')) {\n // geocoding error\n msg.payload.message = \"Unknown Location - Probably over the ocean.\";\n\n var lat_string = msg.mydata.position.lat.toString();\n msg.payload.lat = Math.round(100*lat_string)/100;\n\n var lon_string = msg.mydata.position.lon.toString();\n msg.payload.lon = Math.round(100*lon_string)/100;\n} else {\n // text-based answer\n if (msg.mode) {\n msg.payload.mode = msg.mode;\n }\n msg.payload.message = msg.text;\n msg.payload.lat = undefined;\n msg.payload.lon = undefined;\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":230,"y":200,"wires":[["3be29982.3c7216"]]},{"id":"3be29982.3c7216","type":"http response","z":"486f3bb0.f64324","name":"Bot response","statusCode":"200","headers":{},"x":460,"y":200,"wires":[]},{"id":"6be3a178.a4764","type":"http in","z":"486f3bb0.f64324","name":"Chat home page","url":"/bot","method":"get","upload":false,"swaggerDoc":"","x":240,"y":640,"wires":[["9f030f5e.287f3"]]},{"id":"9f030f5e.287f3","type":"template","z":"486f3bb0.f64324","name":"HTML","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!--\n# Copyright 2018 IBM\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n-->\n\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>\n\t My BOT\n\t</title>\n\t<link rel=\"stylesheet\"\n type=\"text/css\"\n href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" />\n\t<style>\n \tbody {\n \t font-family: monospace;\n \t}\n\t .sat-track {\n\t display: flex;\n\t height: 100%;\n font-family: monospace;\n\t }\n\t \n\t .sat-track--chat {\n\t width: 30%;\n\t max-width: 400px;\n\t border-right: 1px solid #929292;\n\t display: flex;\n\t flex-direction: column;\n\t }\n\t \n\t .sat-track--chat--logs {\n\t flex-grow: 1;\n\t background-color: #262626;\n\t height: 70%;\n overflow-y: scroll;\n\t }\n\t \n\t .sat-track--chat--message {\n width: 100%;\n margin-top: 12px;\n display: flex;\n\t }\n\t \n\t .sat-track--chat--message div {\n\t border-radius: 6px;\n width: 60%;\n color: white;\n padding: 6px 12px;\n\t }\n\t \n\t .sat-track--chat--you div {\n\t background-color: #4eb8ff;\n margin-left: 6px;\n border-bottom-left-radius: 0px;\n\t }\n\t \n\t .sat-track--chat--bot,\n\t .sat-track--chat--error {\n\t flex-direction: row-reverse;\n\t }\n\t \n\t .sat-track--chat--bot div,\n\t .sat-track--chat--error div {\n\t background-color: #97b83a;\n margin-right: 6px;\n border-bottom-right-radius: 0px;\n\t }\n\t \n\t .sat-track--chat--error div {\n\t background-color: #cc5f5f;\n\t }\n\t \n\t .sat-track--chat form {\n\t background-color: #141414;\n margin-bottom: 0px;\n color: white;\n\t }\n\t \n\t .sat-track--chat label {\n\t display: block;\n padding: 6px;\n margin-bottom: 0px;\n border-bottom: 1px solid #434343;\n\t }\n\t \n\t .sat-track--chat textarea {\n \t resize: none;\n width: 100%;\n min-height: 50px;\n color: black;\n padding: 6px;\n\t }\n\t \n\t .sat-track--chat button {\n \t width: 100%;\n padding: 6px 6px;\n font-size: 12pt;\n background: #268cb4;\n border: 1px solid #02b8ff;\n color: white;\n\t }\n\t \n\t .sat-track--chat button:hover {\n\t cursor: pointer;\n background: #97b83a;\n border: 1px solid #02b8ff;\n color: white;\n\t }\n\t \n\t h1 {\n\t margin: 0px;\n background-color: black;\n color: #eee;\n padding: 12px 6px;\n font-size: 16pt;\n border-bottom: 1px solid #00b8ff;\n\t }\n\t \n\t .sat-track--map {\n\t width: 100%;\n\t }\n\t \n\t .sat-track--map iframe {\n\t width: 100%;\n\t height: 100%;\n\t }\n\t \n\t .sat-track--map small {\n\t position: absolute;\n bottom: 0px;\n\t }\n\t \n\t</style>\n </head>\n <body>\n\n <div class=\"container\">\n <div id=\"no-script\"class=\"bg-info\">\n This application needs JavaScript enabled in your browser!\n </div>\n <div id=\"id_contextdump\"></div>\n </div>\n \n <div class=\"sat-track\">\n <div class=\"sat-track--chat\">\n <h1>ISS Tracker BOT</h1>\n <div class=\"sat-track--chat--logs\" id=\"id_botchathistory\"></div>\n \t <div>\n \t <form>\n <label for=\"id_chattext\">Your Input: </label>\n <textarea type=\"text\" name=\"chattext\" id=\"id_chattext\"></textarea>\n \t </form>\n \t <button onclick=\"javascript:onChatClick()\" id=\"id_enter\">Send</button>\n \t </div>\n </div>\n <div class=\"sat-track--map\" id=\"WorldMap\">\n <iframe id=\"mode-iframe\" width=\"800\" height=\"600\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"./worldmap\"></iframe>\n <br /><small><a id=\"mode-link\" href=\"./worldmap\" style=\"color:#0000FF;text-align:left\">View Larger Map</a></small>\n </div>\n </div>\n\t \n <script type=\"text/javascript\" src=\"https://code.jquery.com/jquery-2.1.4.min.js\"></script>\n <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>\n\n <script>\n $(document).ready(function() {\n javascriptCheck();\n $('#id_contextdump').hide();\n enterbutton();\n //invokeAjax (\"Hello\");\n });\n \n // if javascript is enabled on the browser then can remove the warning message\n function javascriptCheck() {\n $('#no-script').remove();\n }\n \n // creates div for interaction with bot \n function createNewDiv(who, message) {\n var txt = who + ': ' + message;\n var container;\n if (who == 'You') {\n container = $('<div class=\"sat-track--chat--message sat-track--chat--you\"></div>');\n } else if (who == 'Error') {\n container = $('<div class=\"sat-track--chat--message sat-track--chat--error\"></div>');\n } else {\n container = $('<div class=\"sat-track--chat--message sat-track--chat--bot\"></div>');\n }\n container.append($('<div></div>').text(txt))\n return container;\n \n }\n \n // appends latest communication with bot to botchathistory\n function chat(person, txt) {\n $('#id_botchathistory').append(createNewDiv(person, txt));\n } \n \n // sets pressing of enter key to perform same action as send button\n function enterbutton(){\n $(function() {\n $(\"form textarea\").keypress(function (e) {\n if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {\n $('#id_enter').click();\n return false;\n } else {\n return true;\n }\n });\n });\n }\n \n // User has entered some text.\n function onChatClick() {\n var txt = $('#id_chattext').val();\n chat('You', txt); \n invokeAjax(txt);\n $('#id_chattext').val('');\n }\n \n function switchMode(mode) {\n if (mode === '3d') {\n document.getElementById('mode-iframe').src = './earth'\n document.getElementById('mode-link').href = './earth'\n } else {\n document.getElementById('mode-iframe').src = './worldmap'\n document.getElementById('mode-link').href = './worldmap'\n }\n \n }\n \n function processOK(response) {\n console.log(response);\n \n if (response.mode) {\n switchMode(response.mode)\n chat('Bot', 'Mode Changed to ' + response.mode)\n } else {\n chat('Bot', response.message);\n if (response.lat && response.lon) {\n // sometimes text response only\n chat('Bot', \"Latitude: \" + response.lat);\n chat('Bot', \"Longitude: \" + response.lon);\n }\n }\n // $('#id_contextdump').data('convContext', response.botresponse.messageout.context);\n }\n \n function processNotOK() {\n chat('Error', 'Error whilst attempting to talk to Bot');\n }\n \n function invokeAjax(message) {\n // var contextdata = $('#id_contextdump').data('convContext');\n // console.error('checking stashed context data');\n // console.error(contextdata);\n \n var ajaxData = {};\n ajaxData.msgdata = message;\n // if (contextdata) {\n // ajaxData.context = contextdata; \n // }\n \n $.ajax({\n type: 'POST',\n url: 'botchat',\n data: ajaxData,\n success: processOK,\n error: processNotOK\n });\n } \n </script>\n </body>\n</html>\n\n","output":"str","x":410,"y":640,"wires":[["bcb61e5c.b796f"]]},{"id":"bcb61e5c.b796f","type":"http response","z":"486f3bb0.f64324","name":"Chat http response","statusCode":"","headers":{},"x":590,"y":640,"wires":[]},{"id":"92c3830f.ccbf5","type":"function","z":"486f3bb0.f64324","name":"ISS to map","func":"msg.mydata = msg.payload;\n\nvar time = new Date(msg.mydata.timestamp)\nmsg.payload = {};\nmsg.payload.name = \"ISS @ \" + time.getHours() + ':' + time.getMinutes() + ' on ' + (1 + time.getMonth()) + '/' + time.getDate() + '/' + time.getFullYear();\nmsg.payload.lat = Math.round(100 * msg.mydata.position.lat)/100;\nmsg.payload.lon = Math.round(100 * msg.mydata.position.lon)/100;\nmsg.payload.layer = \"ISS\";\nmsg.payload.zoom = 15;\nmsg.payload.icon = \"iss\";\n\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":820,"wires":[["1c5b3749.6b8779","23ed9cfa.493404","f0764250.40e8e"]]},{"id":"2d380e71.850932","type":"inject","z":"486f3bb0.f64324","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"0.1","x":310,"y":760,"wires":[["77effbbc.2c9674"]]},{"id":"77effbbc.2c9674","type":"function","z":"486f3bb0.f64324","name":"add map layer","func":"msg.payload = {};\nmsg.payload.command = {};\n\nvar u = 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png';\nvar o = JSON.stringify({ maxZoom: 2, attribution: '© OpenStreetMap'});\n\nmsg.payload.command.map = {name:\"OSMhot\", url:u, opt:o};\nmsg.payload.command.layer = \"OSMhot\";\n\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":760,"wires":[["1c5b3749.6b8779"]]},{"id":"f0764250.40e8e","type":"function","z":"486f3bb0.f64324","name":"move and zoom","func":"msg.payload = { \n command:{\n layer:\"Esri Terrain\",\n lat:msg.payload.lat,\n lon:msg.payload.lon,\n zoom:4\n }\n};\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":800,"wires":[["1c5b3749.6b8779"]]},{"id":"54f1e3c7.41a94c","type":"function","z":"486f3bb0.f64324","name":"iss to reverse geocode function`","func":"msg.mydata = msg.payload;\n//msg.payload = {};\n//msg.payload = {};\nmsg.lat = msg.payload.position.lat;\nmsg.lon = msg.payload.position.lon;\n\nreturn msg;\n//return [msg, msg];","outputs":1,"noerr":0,"x":250,"y":140,"wires":[["4a85a76d.4c4f38"]]},{"id":"45aa3bc2.bb4ea4","type":"http request","z":"486f3bb0.f64324","name":"Get reverse geocode ","method":"GET","ret":"txt","url":"https://us1.locationiq.org/v1/reverse.php?key={{{API_key}}}&lat={{{lat}}}&lon={{{lon}}}&format=json","tls":"","x":720,"y":140,"wires":[["801fe924.b61628"]]},{"id":"801fe924.b61628","type":"json","z":"486f3bb0.f64324","name":"","pretty":false,"x":890,"y":140,"wires":[["c590882d.d15a38"]]},{"id":"88bff56e.c7cef8","type":"link in","z":"486f3bb0.f64324","name":"iss to reverse geocode IN","links":["5fac50df.a44fb"],"x":75,"y":140,"wires":[["54f1e3c7.41a94c"]]},{"id":"96ac16eb.05e9a8","type":"comment","z":"486f3bb0.f64324","name":"Watson Assistant Chat API","info":"","x":443,"y":40,"wires":[]},{"id":"5b0bf09e.edb8a","type":"comment","z":"486f3bb0.f64324","name":"HTML Chat UI","info":"","x":410,"y":600,"wires":[]},{"id":"aafd16c.cd574e8","type":"comment","z":"486f3bb0.f64324","name":"World Map UI","info":"","x":410,"y":720,"wires":[]},{"id":"36c196f5.ffe01a","type":"link in","z":"486f3bb0.f64324","name":"Assistant output to Chat IN","links":["110bb759.55ba19","8baa515e.0cd27","8f5c8076.2b4d","c590882d.d15a38","c99beae8.2695a8"],"x":75,"y":200,"wires":[["8de58684.0ec738"]]},{"id":"c590882d.d15a38","type":"link out","z":"486f3bb0.f64324","name":"json OUT","links":["36c196f5.ffe01a"],"x":975,"y":140,"wires":[]},{"id":"68a7b75d.f42138","type":"link in","z":"486f3bb0.f64324","name":"ISS to Map IN","links":["5fac50df.a44fb","8baa515e.0cd27"],"x":135,"y":820,"wires":[["92c3830f.ccbf5","5d5491e.cc8137"]]},{"id":"e04535cd.ce0cc8","type":"switch","z":"486f3bb0.f64324","name":"Assistant Intents","property":"assistant.intents[0].intent","propertyType":"msg","rules":[{"t":"eq","v":"what","vt":"str"},{"t":"eq","v":"where","vt":"str"},{"t":"eq","v":"where-historical","vt":"str"},{"t":"eq","v":"where-future","vt":"str"},{"t":"eq","v":"mode-2d","vt":"str"},{"t":"eq","v":"mode-3d","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":190,"y":420,"wires":[["d85fb72b.9577a8"],["8419df17.94cce"],["a20c302c.4a2fd"],["d5bfe8f5.9e1a18"],["91a54a36.1f7cd8"],["bbeea767.135d58"]]},{"id":"68b93215.de04ec","type":"link out","z":"486f3bb0.f64324","name":"Generate Timestamp OUT","links":["55adb9d7.d50118"],"x":795,"y":80,"wires":[]},{"id":"55adb9d7.d50118","type":"link in","z":"486f3bb0.f64324","name":"Assistant Intents IN","links":["68b93215.de04ec"],"x":55,"y":420,"wires":[["e04535cd.ce0cc8"]]},{"id":"5fac50df.a44fb","type":"link out","z":"486f3bb0.f64324","name":"ISS Location OUT","links":["68a7b75d.f42138","88bff56e.c7cef8"],"x":555,"y":360,"wires":[]},{"id":"e35ee5cb.ac4798","type":"function","z":"486f3bb0.f64324","name":"ISS Path to Line","func":"points = [];\n\nmsg.payload.forEach(function(p) {\n points.push([p.position.lat, p.position.lon])\n})\n\nmsg.payload = {\n name: 'Path',\n line: points,\n layer: \"ISS\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":900,"wires":[["1c5b3749.6b8779"]]},{"id":"9cf64931.ff99c8","type":"link in","z":"486f3bb0.f64324","name":"ISS Path to Line IN","links":["8baa515e.0cd27"],"x":335,"y":900,"wires":[["e35ee5cb.ac4798","5d5491e.cc8137"]]},{"id":"8baa515e.0cd27","type":"link out","z":"486f3bb0.f64324","name":"ISS 2 OUT","links":["36c196f5.ffe01a","68a7b75d.f42138","9cf64931.ff99c8"],"x":875,"y":420,"wires":[]},{"id":"efd03cc.9a247c","type":"comment","z":"486f3bb0.f64324","name":"Handle Assistant Intents","info":"","x":410,"y":280,"wires":[]},{"id":"1a4f18d1.98f1f7","type":"function","z":"486f3bb0.f64324","name":"Define Text","func":"msg.text = 'Showing Last 10 Mins'\n\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":400,"wires":[["1370faac.08e1b5"]]},{"id":"866f1eb1.95a73","type":"function","z":"486f3bb0.f64324","name":"Define Text","func":"msg.text = 'Showing Next 10 Mins'\n\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":440,"wires":[["1370faac.08e1b5"]]},{"id":"d85fb72b.9577a8","type":"function","z":"486f3bb0.f64324","name":"What is the ISS?","func":"msg.text = 'The International Space Station (ISS) is a habitable artificial satellite in low Earth orbit (~400km). It has between 3 and 6 astronauts onboard at any giving time and serves as a microgravity and space environment research laboratory.'\n\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":320,"wires":[["8f5c8076.2b4d"]]},{"id":"8f5c8076.2b4d","type":"link out","z":"486f3bb0.f64324","name":"What is ISS OUT","links":["36c196f5.ffe01a"],"x":555,"y":320,"wires":[]},{"id":"1c5b3749.6b8779","type":"worldmap","z":"486f3bb0.f64324","name":"","lat":"","lon":"","zoom":"","layer":"","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","x":765,"y":821,"wires":[]},{"id":"23ed9cfa.493404","type":"worldmap-tracks","z":"486f3bb0.f64324","depth":20,"name":"","x":485,"y":861,"wires":[["1c5b3749.6b8779"]]},{"id":"8419df17.94cce","type":"satellite","z":"486f3bb0.f64324","sattype":"stations","satid":"ISS (ZARYA)","name":"scottda","x":410,"y":360,"wires":[["5fac50df.a44fb"]]},{"id":"1370faac.08e1b5","type":"satellite","z":"486f3bb0.f64324","sattype":"stations","satid":"ISS (ZARYA)","name":"scottda","x":770,"y":420,"wires":[["8baa515e.0cd27"]]},{"id":"a20c302c.4a2fd","type":"timearray","z":"486f3bb0.f64324","plus":0,"minus":"10","samples":"20","name":"Last 10 Mins","x":410,"y":400,"wires":[["1a4f18d1.98f1f7"]]},{"id":"d5bfe8f5.9e1a18","type":"timearray","z":"486f3bb0.f64324","plus":"10","minus":"0","samples":"20","name":"Next 10 Mins","x":410,"y":440,"wires":[["866f1eb1.95a73"]]},{"id":"4a85a76d.4c4f38","type":"credentials","z":"486f3bb0.f64324","name":"Credentials","props":[{"value":"API_key","type":"msg"}],"x":485,"y":141,"wires":[["45aa3bc2.bb4ea4"]]},{"id":"5d5491e.cc8137","type":"earth","z":"486f3bb0.f64324","name":"","x":450,"y":940,"wires":[]},{"id":"91a54a36.1f7cd8","type":"function","z":"486f3bb0.f64324","name":"Define Mode","func":"msg.mode = '2d'\n\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":480,"wires":[["110bb759.55ba19"]]},{"id":"bbeea767.135d58","type":"function","z":"486f3bb0.f64324","name":"Define Mode","func":"msg.mode = '3d'\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":520,"wires":[["c99beae8.2695a8"]]},{"id":"110bb759.55ba19","type":"link out","z":"486f3bb0.f64324","name":"Define Mode 2d OUT","links":["36c196f5.ffe01a"],"x":515,"y":480,"wires":[]},{"id":"c99beae8.2695a8","type":"link out","z":"486f3bb0.f64324","name":"Define Mode 3d OUT","links":["36c196f5.ffe01a"],"x":515,"y":520,"wires":[]}]