Live Tracking the International Space Station
During last October’s Python Boston User meetup, we put together this simple but fun project. Because this was a software meet up -not a hardware one- my goal was to read some already-available real-time data and make sense of it through the Ubidots service.
Luckily I found this service made possible by Nathan Bergey which updates the ISS position in real-time. By reading its live data we are able to measure the distance between the ISS and Boston, and then post the whole data to Ubidots
How about triggering an HTTP URL that turns a light on every time the station flies over your head?
We present the source code below. You can insert your own API key and variable id, change the coordinates to match your location and then it should work as shown above. To learn how to send a GeoPoint 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 on the earth. It doesn’t reflect real sighting opportunities as this depends on more variables than just proximity (i.e. time of the day).
Have a project idea to track something in real time?
Click here to get started
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()