IoT Projects

Tracking the International Space Station with Ubidots

Agustin Pelaez
· 3 min read
Send by email

Are you a space enthusiast and dream to reach the stars one day? This quick and simple project might just be your first step to getting there. Track the International Space Station with Ubidots and receive an alert every time the station passes by.

The International Space Station (ISS) is a low orbit, manned satellite that has been conducting experiments and collecting space data since its initial launch in November 1998. Housing 6 crew members at a time, this craft is constantly orbiting the earth and relaying millions of data points each day. Data that is used in space, chemical, biological, and phycological research to benefit all of us still occupying Earth.

Last year, IT leaders Texas Instrument and NASA joined up to increase the awareness and activity of middle graders and high school students to explore science, technology, engineering and mathematics (STEM) and engage them to problem solving, reason, and model to practices the core STEM curriculum that professionals use every day to support the International Space Station.

As supporters of STEM and all things IT, Ubidots and our engineers wanted to join in on the fun and find a way to utilize our IoT software with some of the cool STEM projects happening in classrooms around the world. And, since STEM, the International Space Station, and Ubidots are all global organizations, what better way to work with the ISS than being able to track it and notify your whenever it is passing overhead.

Using the Open Notify made possible by Nathan Bergey you can easily send updates of the ISS position in real-time to Ubidots. By reading its live data from Open Notify we are able to measure the distance between the ISS and Boston (when I author this blog), and then post the whole data to Ubidots for your viewing pleasure.

To do this, enter and update source code below with your Raspberry Pi’s text editor. Be sure to update your credentials with your own API key and variable id, plus changing the coordinates to match your location. To learn how to send a context to the Ubidots API, check out our documentation.

Note: This script is just tracking the ISS position and using a standard formula to calculate its distance to a specific point in earth. It doesn’t reflect real sighting opportunities as this depends on more on weather and time variables than simply proximity (i.e. location relative to you).

Have a project idea to track something in real time?

Click here to get started with Ubidots.

from ubidots import ApiClient
import requests,time
from math import *

#Connect to Ubidots

api = ApiClient('a21ebaf64e14d195c0044fcxxb9f6dab9d653af3')

#Instantiate local variable from Ubidots

local_distance = api.get_variable('54ca7a2176254xxxfd4b9493f')

def main():

	while(1):
	    #Get current ISS position
	    req_iss = requests.get('http://api.open-notify.org/iss-now.json')
	    dict = req_iss.json()
	    latlong = dict['iss_position'];
	    lat1 = latlong['latitude']
	    lon1 = latlong['longitude']
	    #Calculate Distance to Home

	    lat2 = 50.085305
	    lon2 = -5.315853

	    d = getDistance(lat1,lon1,lat2,lon2)
	    d = round(d,1)
	    #Send value to Ubidots
	    local_distance.save_value({'value':d,'context':{'lat':lat1,'lng':lon1}})
	    time.sleep(1)

def getDistance(lat1,lon1,lat2,lon2):
    R = 6371; 					#Radius of the earth in km
    dLat = deg2rad(lat2-lat1);  # deg2rad below
    dLon = deg2rad(lon2-lon1); 
    a = sin(dLat/2) * sin(dLat/2) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * sin(dLon/2) * sin(dLon/2) 
    c = 2 * atan2(sqrt(a), sqrt(1-a)); 
    d = R * c; 					# Distance in km
    return d;

def deg2rad(deg):
  return deg * (pi/180)

if __name__ == '__main__':
	main()

Once the data is being sent to Ubidots, you can schedule an alert to trigger an event whenever the station is passing nearby. Here we built a notification that whenever the ISS is less than 300m away from Boston, I will receive an email.

Project Notice: This script is tracking the ISS position and using a standard formula to calculate its distance to a specific point on earth. This will not reflect real sighting opportunities as this depends on more than simply proximity (i.e. time of the day and weather).

Happy hacking 🙂