Satellite tracking works. Added two new 📡 in json
This commit is contained in:
parent
bc59545f4b
commit
fe45d1852b
110
src/main.py
Normal file
110
src/main.py
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
from rtlsdr.rtlsdrtcp import RtlSdrTcpClient
|
||||||
|
from configparser import ConfigParser
|
||||||
|
import predict
|
||||||
|
from json import loads
|
||||||
|
from logging import getLogger, basicConfig, INFO, info, warning
|
||||||
|
from datetime import datetime
|
||||||
|
from multiprocessing.pool import Pool
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
basicConfig(level=INFO)
|
||||||
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read("config.ini")
|
||||||
|
|
||||||
|
def predict_satellite_passes():
|
||||||
|
# Predicts satellite passes and returns value until next
|
||||||
|
qth = (config.getfloat("LOCATION", "LAT"), config.getfloat("LOCATION", "LON"), config.getfloat("LOCATION", "ALT"))
|
||||||
|
with open("tle.json", "r") as f:
|
||||||
|
tle = loads(f.read())
|
||||||
|
|
||||||
|
passes = []
|
||||||
|
for i in tle:
|
||||||
|
observation = predict.observe(tle[i]["tle"], qth)
|
||||||
|
info(f"Observing {observation['name']}, ID: {observation['norad_id']}")
|
||||||
|
transit= predict.transits(tle[i]["tle"], qth)
|
||||||
|
transit = next(transit)
|
||||||
|
|
||||||
|
delta = datetime.now().fromtimestamp(transit.start) - datetime.now()
|
||||||
|
passes.append({
|
||||||
|
"name": observation["name"],
|
||||||
|
"freq": int(float(tle[i]["freq"])*10**6),
|
||||||
|
"start": datetime.now().fromtimestamp(transit.start).isoformat(),
|
||||||
|
"duration": round(transit.duration()/60, 2) ,
|
||||||
|
"max_elevation": round(transit.peak()["elevation"], 2),
|
||||||
|
"passing_soon": delta.seconds if delta.seconds < 10*60 else False
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
return passes
|
||||||
|
|
||||||
|
def upload_to_discord():
|
||||||
|
# Uploads the image to discord
|
||||||
|
pass
|
||||||
|
|
||||||
|
def generate_image():
|
||||||
|
# Generates an image for the satellite pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def record_audio():
|
||||||
|
# Connect to a remote rtl_tcp server
|
||||||
|
sdr = RtlSdrTcpClient(hostname=config.get("RADIO", "HOSTNAME"), port=config.getint("RADIO", "PORT"))
|
||||||
|
|
||||||
|
# Configure the SDR
|
||||||
|
sdr.set_sample_rate(config.getint("RADIO", "SAMPLERATE"))
|
||||||
|
#TODO: Add bandwidth
|
||||||
|
sdr.set_center_freq(config.getfloat("RADIO", "FREQUENCY")*10**6)
|
||||||
|
sdr.set_gain('auto') # Change if you know what you're doing
|
||||||
|
|
||||||
|
def satellite_tracking(satellite):
|
||||||
|
# Brings all the functions together
|
||||||
|
if satellite["passing_soon"]:
|
||||||
|
info(f"Passing soon: {satellite['name']}")
|
||||||
|
sleeper = satellite["passing_soon"]
|
||||||
|
while sleeper > 0:
|
||||||
|
if sleeper % 100 == 0:
|
||||||
|
warning(f"Passing soon: {satellite['name']}, {sleeper} seconds left")
|
||||||
|
elif sleeper <= 10:
|
||||||
|
warning(sleeper)
|
||||||
|
sleeper -= 1
|
||||||
|
sleep(1)
|
||||||
|
# Everything else goes here
|
||||||
|
else:
|
||||||
|
sleeper = datetime.fromisoformat(satellite["start"]).timestamp() - datetime.now().timestamp()
|
||||||
|
|
||||||
|
info(f"{satellite['name']} is not passing soon, sleeping until then :) (sleeping for {str(round(sleeper/(60*60),1)) + ' hours' if sleeper>60*60 else str(round(sleeper/60)) + ' minutes'})")
|
||||||
|
sleep(sleeper)
|
||||||
|
|
||||||
|
# Example of parallel running function
|
||||||
|
# Remember to add to pool
|
||||||
|
# p.apply_async(debugging)
|
||||||
|
# And to increase process count
|
||||||
|
# def parallel_func_example():
|
||||||
|
# while True:
|
||||||
|
# print("Hey, I can run right here, forever!")
|
||||||
|
# sleep(1)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
# Predict passes and get ready to loop
|
||||||
|
while True:
|
||||||
|
passes = predict_satellite_passes()
|
||||||
|
|
||||||
|
# Pool to run for all sattelites
|
||||||
|
p = Pool(processes=len(passes)+1)
|
||||||
|
|
||||||
|
p.map(satellite_tracking, passes)
|
||||||
|
|
||||||
|
# When everything is finished, sleep for 5 seconds and restart
|
||||||
|
sleep(5)
|
||||||
|
|
||||||
|
## TODO:
|
||||||
|
# Record audio
|
||||||
|
# Generate image
|
||||||
|
# Upload to discord
|
||||||
|
# Glue them together
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
10
tle.json
Normal file
10
tle.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"Noaa 19": {
|
||||||
|
"tle":"NOAA 19\n1 33591U 09005A 23170.51864909 .00000231 00000+0 14945-3 0 9991\n2 33591 99.0990 216.4830 0013059 233.6224 126.3743 14.12772246740017",
|
||||||
|
"freq": 137.100
|
||||||
|
},
|
||||||
|
"Noaa 17": {
|
||||||
|
"tle":"NOAA 17\n1 27453U 02032A 23170.53725030 .00000190 00000+0 99394-4 0 9993\n2 27453 98.7163 117.4322 0010669 287.0691 72.9319 14.25314386 91145",
|
||||||
|
"freq": 137.620
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user