Skip to content

Instantly share code, notes, and snippets.

@davidhoness
Created August 5, 2020 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidhoness/70c5ddb8b1700f10ca0eb8dc3d5a485d to your computer and use it in GitHub Desktop.
Save davidhoness/70c5ddb8b1700f10ca0eb8dc3d5a485d to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import urllib.request
import math
import ephem
import time
import sys
import ssl
import pyperclip
import pyautogui
C = 300000000.0
F0 = 145800000.0
LATITUDE = "50.0524" # Goonhilly
LONGITUDE = "-5.1823"
ALTITUDE = 20
class tle_reader(object):
"""
For keeping ephem two line element sets up to date
"""
def __init__(self,
tle_name="ISS (ZARYA)",
tle_file="https://celestrak.com/NORAD/elements/stations.txt",
tle_max_age=3600):
self._tle_name = tle_name
self._tle_file = tle_file
self._tle_max_age = tle_max_age
self._tle = None
self.reload()
def build_index(self, tle_lines):
index = {}
for i in range(0, len(tle_lines), 3):
index[tle_lines[i].strip()] = (tle_lines[i + 1], tle_lines[i + 2])
return index
def reload(self):
print("Loading: %s" % self._tle_file)
try:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(self._tle_file, context=ctx) as response:
tle_lines = response.read().decode("utf-8").splitlines()
index = self.build_index(tle_lines)
tle_data = index[self._tle_name]
self._tle = ephem.readtle(self._tle_name, tle_data[0], tle_data[1])
except Exception as e:
print(e)
self._tle_age = time.time()
@property
def tle(self):
return self._tle
@property
def tle_expired(self):
return time.time() - self._tle_age > self._tle_max_age
def web_sdr_set_freq(fmhz):
fkhz = fmhz / 1000.0
pyperclip.copy(str(fkhz))
pyautogui.press('g')
pyautogui.hotkey('ctrl', 'v')
pyautogui.press('enter')
iss = tle_reader(tle_name="ISS (ZARYA)", tle_max_age=5520) # 92 minutes
print('\n\nNote: This script creates keyboard events on the WebSDR browser window for Doppler tuning. Only the freqeuncy is changed. Set band/mode yourself, Allow keyboard = ON and leave the WebSDR focussed')
if iss.tle is None:
sys.exit(0)
myloc = ephem.Observer()
myloc.lon = LONGITUDE
myloc.lat = LATITUDE
myloc.elevation = ALTITUDE
freq = F0
running = True
try:
while running:
myloc.date = time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime())
iss.tle.compute(myloc)
alt = math.degrees(iss.tle.alt)
if alt > 0: # iss is flying over our location
new_freq = int(F0 - iss.tle.range_velocity * F0 / C) # doppler
if new_freq != freq:
print(new_freq, round(alt, 2), myloc.date)
web_sdr_set_freq(new_freq) # set new frequency in web_sdr
time.sleep(.5)
freq = new_freq
elif iss.tle_expired:
iss.reload() # we could be running for days / weeks
else:
time.sleep(10) # do nothing, wait for iss to arrive
freq = F0
except KeyboardInterrupt:
running = False
print("Bye")
@davidhoness
Copy link
Author

Install the following additional python libraries

  • pyperclip
  • PyAutoGUI
  • ephem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment