Calculate how far away from the International Space Station you are.

ISS Distance calculation

This flow takes your Latitude and Longitude and calculates how far away from the ISS you currently are and returns it in a msg object. The code was adapted from Linux Voice's Issue 6: International Space Station detector which is also worth a read!

HTTPS fix

The API uses https and cause a UNABLE_TO_VERIFY_LEAF_SIGNATURE which will crash node. Currently my work around is to launch node-red in this way:

NODE_TLS_REJECT_UNAUTHORIZED=0 node red.js

Although being less secure, it should now allow you to communicate with the API.

Have fun!

-James

[{"id":"e1089333.1ef77","type":"inject","name":"Trigger ISS Distance Check","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":179,"y":94,"z":"56b706ba.a948f8","wires":[["943513b6.6bcaf"]]},{"id":"943513b6.6bcaf","type":"http request","name":"Get ISS Location","method":"GET","url":"http://api.wheretheiss.at/v1/satellites/25544","x":411,"y":94,"z":"56b706ba.a948f8","wires":[["19d3c8af.e62c37"]]},{"id":"19d3c8af.e62c37","type":"function","name":"Sort the Data","func":"var iss_json = JSON.parse(msg.payload);\nvar iss_lat = iss_json.latitude;\nvar iss_long = iss_json.longitude;\nvar home_lat = 51.026551;\nvar home_long = -1.398004;\n\n\n\nmsg.payload = {};\nmsg.payload.iss_lat = iss_lat;\nmsg.payload.iss_long = iss_long;\nmsg.payload.home_lat = home_lat;\nmsg.payload.home_long = home_long;\nreturn msg;","outputs":1,"x":399.5,"y":134,"z":"56b706ba.a948f8","wires":[["7746cae5.88b934"]]},{"id":"7746cae5.88b934","type":"function","name":"Calculate Distance","func":"var degrees_to_radians = Math.PI/180.0;\n\nvar phi1 = (90.0 - msg.payload.home_lat)*degrees_to_radians;\nvar phi2 = (90.0 - msg.payload.iss_lat)*degrees_to_radians;\nvar theta1 = msg.payload.home_long*degrees_to_radians;\nvar theta2 = msg.payload.iss_long*degrees_to_radians;\nvar cos = (Math.sin(phi1)*Math.sin(phi2)*Math.cos(theta1 - theta2) + Math.cos(phi1)*Math.cos(phi2));\nvar arc = Math.acos( cos );\nvar distance = arc *3960;\nmsg.payload.distance = distance;\nreturn msg;","outputs":1,"x":416.5,"y":174,"z":"56b706ba.a948f8","wires":[["a2b97921.5d4688"]]},{"id":"a2b97921.5d4688","type":"debug","name":"","active":true,"console":false,"complete":false,"x":605,"y":167,"z":"56b706ba.a948f8","wires":[]}]

Flow Info

Created 11 years, 1 month ago
Updated 5 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x2)
  • http request (x1)
  • inject (x1)

Tags

  • ISS
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option