Fix jwt-token

This commit is contained in:
2025-08-18 07:37:15 +02:00
parent 4c7a69baed
commit 0962920f1b

View File

@@ -16,6 +16,9 @@ from datetime import datetime, timedelta
API_BASE_URL = "http://selfservice.cqers.com/drones/api" API_BASE_URL = "http://selfservice.cqers.com/drones/api"
# Alternative for local testing: "http://localhost:3002/api" # Alternative for local testing: "http://localhost:3002/api"
# Debug configuration
DEBUG_MODE = False # Set to True to enable payload debugging
# Global variable to store devices fetched from API # Global variable to store devices fetched from API
DEVICES = [] DEVICES = []
@@ -262,6 +265,17 @@ def send_detection(detection_data):
"Content-Type": "application/json" "Content-Type": "application/json"
} }
# Debug output - show complete payload being sent
if DEBUG_MODE:
print("\n" + "="*60)
print("🐛 DEBUG: Sending payload to backend")
print("="*60)
print(f"URL: {url}")
print(f"Headers: {json.dumps(headers, indent=2)}")
print("Payload:")
print(json.dumps(detection_data, indent=2, sort_keys=True))
print("="*60 + "\n")
try: try:
response = requests.post(url, json=detection_data, headers=headers, timeout=10) response = requests.post(url, json=detection_data, headers=headers, timeout=10)
@@ -271,10 +285,14 @@ def send_detection(detection_data):
return True return True
else: else:
print(f"❌ Failed: {response.status_code} - {response.text}") print(f"❌ Failed: {response.status_code} - {response.text}")
if DEBUG_MODE:
print(f"🐛 DEBUG: Response body: {response.text}")
return False return False
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print(f"❌ Network error: {e}") print(f"❌ Network error: {e}")
if DEBUG_MODE:
print(f"🐛 DEBUG: Exception details: {str(e)}")
return False return False
def simulate_orlan_detection_test(): def simulate_orlan_detection_test():
@@ -380,13 +398,15 @@ def simulate_orlan_detection_test():
"drone_type": 1, # Orlan/Military type "drone_type": 1, # Orlan/Military type
"rssi": rssi, "rssi": rssi,
"freq": 24, # 2.4 GHz "freq": 24, # 2.4 GHz
"drone_id": drone_id "drone_id": drone_id,
"_distance": distance_km # Helper field for logging
} }
try: # Use centralized send_detection function for consistent debug output
response = requests.post(f"{API_BASE_URL}/detections", json=detection_data) success = send_detection(detection_data)
if response.status_code == 201: if success:
status = "🚨 CRITICAL ALERT" if distance_km <= 5 else "⚠️ DETECTED" status = "🚨 CRITICAL ALERT" if distance_km <= 5 else "⚠️ DETECTED"
if not DEBUG_MODE: # Avoid duplicate output when debugging
print(f"{status} - Step {step}/{total_steps}: Distance={distance_km:.1f}km, RSSI={rssi}dBm") print(f"{status} - Step {step}/{total_steps}: Distance={distance_km:.1f}km, RSSI={rssi}dBm")
# Show escalation messages # Show escalation messages
@@ -398,8 +418,8 @@ def simulate_orlan_detection_test():
elif distance_km <= 0.1: elif distance_km <= 0.1:
print(f"💥 DIRECTLY OVERHEAD: Orlan at {distance_km*1000:.0f}m altitude!") print(f"💥 DIRECTLY OVERHEAD: Orlan at {distance_km*1000:.0f}m altitude!")
else: else:
print(f"❌ Failed to send detection: {response.status_code}") print(f"❌ Failed to send Orlan detection at step {step}")
except Exception as e: continue
print(f"❌ Error sending detection: {e}") print(f"❌ Error sending detection: {e}")
else: else:
# Outside detection range # Outside detection range