ISS Location (US-based_
A single flow that provides a simple HTTP JSON API for requesting the next overhead pass of the International Space Station (ISS) - this code is based on a valid location - this differs from the original version which used a valid UK Postal code (see: The original UK based flow)
API Description
Once the flow is deployed an /iss HTTP endpoint will be created taking a single query parameter: locatio=xxxxxxx.
Example of an HTTP GET request against the API:
<hostname>:<port>/iss?location=carmel,ny
Output field | Field Description | Example of Format |
---|---|---|
message | Request Status | "Success" |
Time | UTC Timestamp of ISS pass | 1570706118 |
strtime | Formatted version of time | "10/10/2021, 11:59:32 AM UTC" |
duration | Duration of pass (in seconds) | 559 |
strduration | Formatted version of duration | "9 minutes 19 seconds) |
[{"id":"99e0b2d0.165bd8","type":"tab","label":"ISS Location (US based)","disabled":false,"info":""},{"id":"fd5c25bb.464fc8","type":"debug","z":"99e0b2d0.165bd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":280,"wires":[]},{"id":"796caeb9.4a8538","type":"change","z":"99e0b2d0.165bd8","name":"","rules":[{"t":"set","p":"longitude","pt":"msg","to":"payload.results[0].geometry.lng","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":130,"y":480,"wires":[["8b86f8e.bb9aa88"]]},{"id":"8b86f8e.bb9aa88","type":"change","z":"99e0b2d0.165bd8","name":"","rules":[{"t":"set","p":"latitude","pt":"msg","to":"payload.results[0].geometry.lat","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":120,"y":560,"wires":[["336759a9.962ea6"]]},{"id":"336759a9.962ea6","type":"http request","z":"99e0b2d0.165bd8","name":"Request next ISS pass","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://api.open-notify.org/iss-pass.json?lat={{latitude}}&lon={{longitude}}&n=10&alt=197","tls":"","persist":false,"proxy":"","authType":"","x":340,"y":560,"wires":[["e9b7851f.71699"]]},{"id":"e9b7851f.71699","type":"function","z":"99e0b2d0.165bd8","name":"Prepare Output","func":"a = msg.payload.response;\n\nvar sched = new Array();\n\nfor (i = 0; i < a.length; i++) {\n var b = new Object();\n duration = msg.payload.response[i].duration;\n risetime = msg.payload.response[i].risetime;\n strTime = new Date(risetime*1000).toLocaleString('en-US', { timeZone: 'UTC', timeZoneName: 'short' });\n dateDuration = new Date(duration*1000);\n strDuration = dateDuration.getMinutes()\n + \" minutes \"\n + dateDuration.getSeconds()\n + \" seconds\";\n \n b[\"Location\"] = msg.location;\n b[\"Time\"] = strTime;\n b[\"Duration\"] = strDuration; \n \n sched.push(b)\n \n} \nmsg.payload = sched;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":560,"wires":[["b2c46706.728ac"]]},{"id":"7785d531.0a300c","type":"http in","z":"99e0b2d0.165bd8","name":"When will the ISS be visible next","url":"/iss","method":"get","upload":false,"swaggerDoc":"","x":170,"y":100,"wires":[["837d1ad1.d11ce8"]]},{"id":"bde2afe4.359258","type":"http request","z":"99e0b2d0.165bd8","name":"Convert US location to lat/long","method":"GET","ret":"obj","paytoqs":"ignore","url":"api.opencagedata.com/geocode/v1/json?key={{{API CODE}}}&q={{{location}}}&countrycode=US","tls":"","persist":false,"proxy":"","authType":"","x":170,"y":300,"wires":[["fd5c25bb.464fc8","9bb751ca.82119"]]},{"id":"837d1ad1.d11ce8","type":"change","z":"99e0b2d0.165bd8","name":"grab location from URL","rules":[{"t":"set","p":"location","pt":"msg","to":"payload.location","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":200,"wires":[["bde2afe4.359258"]]},{"id":"b2c46706.728ac","type":"http response","z":"99e0b2d0.165bd8","name":"Return results to Browser","statusCode":"","headers":{},"x":810,"y":560,"wires":[]},{"id":"9bb751ca.82119","type":"switch","z":"99e0b2d0.165bd8","name":"Check for Error","property":"payload.total_results","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"gt","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":120,"y":380,"wires":[["5a84d003.b7ee08"],["796caeb9.4a8538"]]},{"id":"5a84d003.b7ee08","type":"function","z":"99e0b2d0.165bd8","name":"Error Message","func":"//a = msg.payload.response;\n//\n//var sched = new Array();\n//\n//for (i = 0; i < a.length; i++) {\n// var b = new Object();\n// duration = msg.payload.response[i].duration;\n// risetime = msg.payload.response[i].risetime;\n// strTime = new Date(risetime*1000).toLocaleString('en-US', { timeZone: 'UTC', timeZoneName: 'short' });\n// dateDuration = new Date(duration*1000);\n// strDuration = dateDuration.getMinutes()\n// + \" minutes \"\n// + dateDuration.getSeconds()\n// + \" seconds\";\n// \n// b[\"Location\"] = msg.location;\n// b[\"Time\"] = strTime;\n// b[\"Duration\"] = strDuration; \n \n// sched.push(b)\n \n//}\n\nvar b = new Object()\n\nvar error_msg = \"Error: \" + msg.location + \" Not found\"\n// b[\"Location:\"] = msg.location;\nb[\"Error:\"] = error_msg;\n\n\n\nmsg.payload = b;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":380,"wires":[["b2c46706.728ac"]]},{"id":"e6712929.96d2a","type":"comment","z":"99e0b2d0.165bd8","name":"Fix API code","info":"# Warning\n\nBe sure to use the Lab's box note to replace the {{API CODE}} with the \"real\" API for opencagedata","x":330,"y":260,"wires":[]}]