This example will help you to learn how to send GPS location to Ubidots using Python. We'll poll 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.

Once the data is there, you can create a Map widget in your Dashboard to see the ISS moving in real-time!

You can also create a Ubidots Event to trigger an alert whenever the station is nearby:

We present the source code below. You can insert your own token and variable id, change the coordinates "lat2" and "lng2" to match your location.

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

#Connect to Ubidots

api = ApiClient(token='xxxxxxxxxxxxxxxxxxxxxxxxxx')

#Instantiate local variable from Ubidots

local_distance = api.get_variable('54ca7a2176254xxxfd4b9493f')

def main():

   #Get current ISS position
   req_iss = requests.get('')
   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

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__':

This script is tracking the ISS position and using a standard formula to calculate its distance to a specific point on earth. It doesn't reflect real sighting opportunities as this depends on more variables than just proximity (i.e. time of the day or weather).

Did this answer your question?