From 8d9d1475005980df844fc3f601d29ff01ce9a2bb Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Sun, 7 Sep 2025 09:13:23 +0200 Subject: [PATCH] Fix jwt-token --- test_orlan_detection.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/test_orlan_detection.py b/test_orlan_detection.py index 514a22b..180c2ab 100644 --- a/test_orlan_detection.py +++ b/test_orlan_detection.py @@ -69,10 +69,13 @@ def is_detectable(distance_km): def fetch_devices(): """Fetch devices from API""" try: - response = requests.get(f"{API_BASE_URL}/devices/map") + response = requests.get(f"{API_BASE_URL}/devices") if response.status_code == 200: data = response.json() return data.get('data', []) + else: + print(f"Failed to fetch devices: {response.status_code}") + print(f"Response: {response.text}") except Exception as e: print(f"Error fetching devices: {e}") return [] @@ -94,16 +97,17 @@ def send_detection(device, drone_lat, drone_lon, distance_km, step, total_steps) } try: - response = requests.post(f"{API_BASE_URL}/detections", json=detection_data) + response = requests.post(f"{API_BASE_URL}/detectors", json=detection_data) if response.status_code == 201: status = "🚨 CRITICAL ALERT" if distance_km <= 5 else "⚠️ DETECTED" if is_detectable(distance_km) else "📡 MONITORING" print(f"{status} - Step {step}/{total_steps}: Distance={distance_km:.1f}km, RSSI={rssi:.0f}dBm") return True else: - print(f"Failed to send detection: {response.status_code}") + print(f"❌ Failed to send detection: {response.status_code}") + print(f"Response: {response.text}") return False except Exception as e: - print(f"Error sending detection: {e}") + print(f"❌ Error sending detection: {e}") return False def calculate_position_along_path(start_lat, start_lon, end_lat, end_lon, progress): @@ -125,13 +129,36 @@ def run_orlan_detection_test(): print("• Critical alerts: <5km from target") print("• End position: Directly overhead (0m)") print("=" * 70) + print(f"🔗 API Endpoint: {API_BASE_URL}") + print() + + # Test API connectivity first + print("🔍 Testing API connectivity...") + try: + response = requests.get(f"{API_BASE_URL}/health") + if response.status_code == 200: + print("✅ API is accessible") + else: + print(f"❌ API health check failed: {response.status_code}") + return + except Exception as e: + print(f"❌ Cannot connect to API: {e}") + print("Please check:") + print("1. Is the server running?") + print("2. Is the API_BASE_URL correct?") + print(f" Current: {API_BASE_URL}") + return # Fetch devices + print("📡 Fetching devices...") devices = fetch_devices() if not devices: print("❌ No devices found!") + print("Make sure at least one device is registered in the system.") return + print(f"✅ Found {len(devices)} device(s)") + # Use the first device as target target_device = devices[0] print(f"🎯 Target Device: {target_device['name']}")