diff --git a/routes/sstv.py b/routes/sstv.py index 5b37870..a934a78 100644 --- a/routes/sstv.py +++ b/routes/sstv.py @@ -359,6 +359,74 @@ def iss_schedule(): }), 500 +@sstv_bp.route('/iss-position') +def iss_position(): + """ + Get current ISS position. + + Query parameters: + latitude: Observer latitude (optional, for elevation calc) + longitude: Observer longitude (optional, for elevation calc) + + Returns: + JSON with ISS current position. + """ + lat = request.args.get('latitude', type=float) + lon = request.args.get('longitude', type=float) + + try: + from skyfield.api import load, wgs84, EarthSatellite + from data.satellites import TLE_SATELLITES + + # Get ISS TLE + iss_tle = TLE_SATELLITES.get('ISS') + if not iss_tle: + return jsonify({ + 'status': 'error', + 'message': 'ISS TLE data not available' + }), 500 + + ts = load.timescale() + satellite = EarthSatellite(iss_tle[1], iss_tle[2], iss_tle[0], ts) + + now = ts.now() + geocentric = satellite.at(now) + subpoint = wgs84.subpoint(geocentric) + + result = { + 'status': 'ok', + 'lat': float(subpoint.latitude.degrees), + 'lon': float(subpoint.longitude.degrees), + 'altitude': float(subpoint.elevation.km), + 'timestamp': now.utc_datetime().isoformat() + } + + # If observer location provided, calculate elevation/azimuth + if lat is not None and lon is not None: + observer = wgs84.latlon(lat, lon) + diff = satellite - observer + topocentric = diff.at(now) + alt, az, distance = topocentric.altaz() + result['elevation'] = float(alt.degrees) + result['azimuth'] = float(az.degrees) + result['distance'] = float(distance.km) + + return jsonify(result) + + except ImportError: + return jsonify({ + 'status': 'error', + 'message': 'skyfield library not installed' + }), 503 + + except Exception as e: + logger.error(f"Error getting ISS position: {e}") + return jsonify({ + 'status': 'error', + 'message': str(e) + }), 500 + + @sstv_bp.route('/decode-file', methods=['POST']) def decode_file(): """ diff --git a/static/js/modes/sstv.js b/static/js/modes/sstv.js index 467637c..9e0ada8 100644 --- a/static/js/modes/sstv.js +++ b/static/js/modes/sstv.js @@ -180,20 +180,11 @@ const SSTV = (function() { const storedLon = localStorage.getItem('observerLon') || -0.1278; try { - const response = await fetch('/satellite/position', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - latitude: parseFloat(storedLat), - longitude: parseFloat(storedLon), - satellites: ['ISS'] - }) - }); - + const response = await fetch(`/sstv/iss-position?latitude=${storedLat}&longitude=${storedLon}`); const data = await response.json(); - if (data.status === 'success' && data.positions?.length > 0) { - issPosition = data.positions[0]; + if (data.status === 'ok') { + issPosition = data; updateIssDisplay(); renderGlobe(); }