Skip to content

Instantly share code, notes, and snippets.

@sh4dowb
Last active August 22, 2021 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4dowb/dc9a6db539db8ce568005650c613aad7 to your computer and use it in GitHub Desktop.
Save sh4dowb/dc9a6db539db8ce568005650c613aad7 to your computer and use it in GitHub Desktop.
satellite_track.py and site source code for https://cagriari.com/satellite/
needs;
rtl_fm
sox
wxtoimg (https://wxtoimgrestored.xyz/beta/wxtoimg-armhf-2.11.2-beta.deb)
wxmap on your server for map generation (https://wxtoimgrestored.xyz/beta/wxtoimg-amd64-2.11.2-beta.deb)
(because wxmap on ARM is not working, at least for me)
python3
requests
noaa-apt
n2yo account and api key
good luck!
<?php
$start = $_GET['start'];
$sat = $_GET['satellite'];
if($_GET['key'] === "-YOUR_SITE_API-"){
exec('wxmap -d -L "lat/lon/alt" -T '.escapeshellarg($sat).' -G "/home/admin/" -H noaa.txt -p 0 -l 0 -o '.escapeshellarg($start).' map.png');
}
NOAA 1 [-]
1 04793U 70106A 19186.83652485 -.00000022 00000-0 14426-3 0 9998
2 04793 101.7027 255.1690 0031345 252.3894 223.9880 12.53990221223003
NOAA 2 (ITOS-D) [-]
1 06235U 72082A 19186.86129802 -.00000022 00000-0 14387-3 0 9997
2 06235 101.7958 153.2285 0004074 349.5395 64.3003 12.53115836137213
NOAA 3 [-]
1 06920U 73086A 19186.89672538 -.00000043 00000-0 13710-4 0 9998
2 06920 102.0508 155.8552 0006769 118.7750 296.1565 12.40341148 67198
NOAA 4 [-]
1 07529U 74089A 19186.93492197 .00000001 00000-0 29016-3 0 9992
2 07529 101.7532 154.4295 0009106 15.6726 51.3029 12.53131133 41577
NOAA 5 [-]
1 09057U 76077A 19186.92099119 -.00000073 00000-0 -22072-3 0 9991
2 09057 101.9325 157.6708 0009889 337.7675 83.3594 12.37751272940417
TIROS N [P]
1 11060U 78096A 19186.74405213 -.00000003 00000-0 20172-4 0 9999
2 11060 98.7892 243.9234 0010543 5.7096 354.4197 14.18237141319086
NOAA 6 [P]
1 11416U 79057A 19186.93092737 .00000012 00000-0 20404-4 0 9993
2 11416 98.6375 181.0166 0010013 190.7155 169.3817 14.33535622 87137
NOAA 7 [-]
1 12553U 81059A 19186.93909711 -.00000024 00000-0 11241-4 0 9993
2 12553 99.0956 194.6802 0010536 296.4570 121.4102 14.17260357965168
NOAA 8 [-]
1 13923U 83022A 19186.90926036 -.00000016 00000-0 10844-4 0 9992
2 13923 98.5823 171.9623 0016187 122.7312 237.5432 14.28676211888542
NOAA 9 [P]
1 15427U 84123A 19186.89677116 .00000001 00000-0 23183-4 0 9999
2 15427 98.8931 135.8122 0014725 350.4991 78.1841 14.16071127784100
NOAA 10 [-]
1 16969U 86073A 19186.89783486 -.00000017 00000-0 10264-4 0 9999
2 16969 98.4788 182.9511 0011121 232.1120 187.2689 14.28073730707034
NOAA 11 [-]
1 19531U 88089A 19186.69290295 -.00000005 00000-0 18448-4 0 9994
2 19531 98.4464 220.0686 0012066 50.1285 310.0949 14.15242613588620
NOAA 12 [-]
1 21263U 91032A 19186.89861611 -.00000028 00000-0 62875-5 0 9998
2 21263 98.5157 201.7916 0012502 251.1713 108.8112 14.25895002463164
NOAA 13 [-]
1 22739U 93050A 19186.66812116 -.00000035 00000-0 32904-5 0 9998
2 22739 98.4707 208.5309 0009399 185.0017 175.1064 14.12732274335119
NOAA 14 [-]
1 23455U 94089A 19186.83923658 -.00000029 00000-0 68708-5 0 9994
2 23455 98.5953 247.4504 0009662 169.3727 190.7652 14.14131701264403
NOAA 15 [B]
1 25338U 98030A 19186.88872122 .00000057 00000-0 42767-4 0 9996
2 25338 98.7457 208.1240 0010285 186.6668 173.4376 14.25919016 99442
NOAA 16 [-]
1 26536U 00055A 19186.85860028 -.00000004 00000-0 20888-4 0 9999
2 26536 98.7747 258.4619 0010433 2.0707 358.0507 14.13231610265146
NOAA 17 [-]
1 27453U 02032A 19186.89200227 -.00000014 00000-0 12335-4 0 9997
2 27453 98.5379 136.8707 0011875 165.6642 194.4877 14.25042755885385
NOAA 18 [B]
1 28654U 05018A 19186.92089028 .00000084 00000-0 70369-4 0 9993
2 28654 99.0945 234.1480 0015235 127.2188 233.0376 14.12435708727858
NOAA 19 [+]
1 33591U 09005A 19186.90386995 .00000078 00000-0 67806-4 0 9995
2 33591 99.1800 178.4439 0013501 334.4381 25.6121 14.12362708536074
SUOMI NPP [+]
1 37849U 11061A 19186.90962545 -.00000004 00000-0 18862-4 0 9999
2 37849 98.7364 124.8692 0001184 107.8070 292.3700 14.19544228398327
NOAA 20 [+]
1 43013U 17073A 19186.86626273 -.00000002 00000-0 19687-4 0 9992
2 43013 98.7209 124.7630 0000809 98.4194 261.7074 14.19558109 84342
import requests, json, time, threading, subprocess, traceback, os, sys
from datetime import datetime
passes = []
satellites = [("28654","NOAA_18", "137.9125M"), ("33591", "NOAA_19", "137.100M"), ("25338","NOAA_15","137.620M")]
def satellite_update():
global passes
while True:
tmppasses = []
try:
for satellite_info in satellites:
resp = json.loads(requests.get("https://www.n2yo.com/rest/v1/satellite/radiopasses/"+satellite_info[0]+"/lat/lon/altitude/days/min_elevation/&apiKey=-N2YO_API_KEY-").text) #min.elevation mine is 40
for sat_pass in resp['passes']:
if sat_pass['maxEl'] > 25:
print(sat_pass, flush=True)
tmppasses.append((sat_pass['startUTC'], sat_pass['endUTC'], satellite_info))
except:
traceback.print_exc()
time.sleep(10)
continue
passes = tmppasses[:]
nextpass = int(sorted(passes[:], key=lambda d: 2147483647 if d[1] < time.time() else d[0])[0][0]) # fix until 2038
try:
requests.get("https://cagriari.com/satellite/nextpass.php?key=-YOUR_SITE_API-&nextpass="+str(nextpass))
except:
traceback.print_exc()
time.sleep(10)
continue
print("Next pass: " + datetime.utcfromtimestamp(nextpass).strftime('%Y-%m-%d %H:%M:%S') + " UTC", flush=True)
time.sleep(60*60*6)
threading.Thread(target=satellite_update).start()
while True:
for sat_pass in passes:
try:
curtime = int(time.time())
if curtime > sat_pass[0] and curtime < sat_pass[1]:
sat_name = sat_pass[2][1]
print("Recording...", flush=True)
p = subprocess.Popen("rtl_fm -d 0 -f "+sat_pass[2][2]+" -s 48000 -g 44 -p 52 -F 9 -A fast -E DC - | sox -t raw -r 48000 -es -b16 -c1 -V1 - "+str(curtime)+"-"+sat_name+".wav rate 11025", shell=True)
time.sleep(int(sat_pass[1] - sat_pass[0]))
os.system("killall rtl_fm")
os.system("killall sox")
time.sleep(5)
print("Recording done, receiving map from server", flush=True)
requests.get("https://cagriari.com/satellite/getmap.php?satellite="+sat_name.replace('_',' ')+"&start="+str(curtime)+"&key=-YOUR_SITE_API-")
open('map.png', 'wb').write(requests.get("https://cagriari.com/satellite/map.png?t="+str(curtime)).content)
p = subprocess.Popen(["noaa-apt", str(curtime)+"-"+sat_name+".wav", "-o", str(curtime)+"-"+sat_name+".png"])
p.wait()
files = {'file': open(str(curtime)+"-"+sat_name+".png",'rb')}
requests.post("https://cagriari.com/satellite/upload.php?apikey=-YOUR_SITE_API-", files=files)
print("Uploaded")
print("Decoding with wxtoimg", flush=True)
p = subprocess.Popen(["wxtoimg","-n","-m","map.png","-t","n","-o","-g","1.6","-e","MSA",str(curtime)+"-"+sat_name+".wav",str(curtime)+"-"+sat_name+".wx.msa.png"])
p.wait()
print("Decoded, uploading", flush=True)
files = {'file': open(str(curtime)+"-"+sat_name+".wx.msa.png",'rb')}
requests.post("https://cagriari.com/satellite/upload.php?apikey=-YOUR_SITE_API-", files=files)
print("Uploaded")
print("Pass ended\n\n\n\n\n",flush=True)
passesx = passes[:]
nextpass = int(sorted(passesx, key=lambda d: 2147483647 if d[1] < time.time() else d[0])[0][0]) # fix until 2038
try:
requests.get("https://cagriari.com/satellite/nextpass.php?key=-YOUR_SITE_API-&nextpass="+str(nextpass))
except:
traceback.print_exc()
time.sleep(10)
continue
print("Next pass: " + datetime.utcfromtimestamp(nextpass).strftime('%Y-%m-%d %H:%M:%S') + " UTC", flush=True)
except:
traceback.print_exc()
time.sleep(1)
<?php
if($_GET['apikey'] == "-YOUR_SITE_API-"){
$check = getimagesize($_FILES["file"]["tmp_name"]);
if($check !== false) {
move_uploaded_file($_FILES["file"]["tmp_name"], "images/".basename($_FILES["file"]["name"]));
$img = imagecreatefrompng("images/".basename($_FILES["file"]["name"]));
$xy = getimagesize("images/".basename($_FILES["file"]["name"]));
$imgresize = imagescale($img, ($xy[0] / $xy[1]) * 400, 400);
imagepng($imgresize, "images/".basename($_FILES["file"]["name"]).".resize.png");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment