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"
# 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
DEVICES = []
@@ -262,6 +265,17 @@ def send_detection(detection_data):
"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:
response = requests.post(url, json=detection_data, headers=headers, timeout=10)
@@ -271,10 +285,14 @@ def send_detection(detection_data):
return True
else:
print(f"❌ Failed: {response.status_code} - {response.text}")
if DEBUG_MODE:
print(f"🐛 DEBUG: Response body: {response.text}")
return False
except requests.exceptions.RequestException as e:
print(f"❌ Network error: {e}")
if DEBUG_MODE:
print(f"🐛 DEBUG: Exception details: {str(e)}")
return False
def simulate_orlan_detection_test():
@@ -380,26 +398,28 @@ def simulate_orlan_detection_test():
"drone_type": 1, # Orlan/Military type
"rssi": rssi,
"freq": 24, # 2.4 GHz
"drone_id": drone_id
"drone_id": drone_id,
"_distance": distance_km # Helper field for logging
}
try:
response = requests.post(f"{API_BASE_URL}/detections", json=detection_data)
if response.status_code == 201:
status = "🚨 CRITICAL ALERT" if distance_km <= 5 else "⚠️ DETECTED"
# Use centralized send_detection function for consistent debug output
success = send_detection(detection_data)
if success:
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")
# Show escalation messages
if distance_km <= 5 and not critical_alerts_started:
print(f"🚨 CRITICAL ALERT: Orlan within {distance_km:.1f}km - AUTO-ESCALATED!")
critical_alerts_started = True
elif distance_km <= 1:
print(f"🔥 IMMEDIATE THREAT: Orlan within facility perimeter!")
elif distance_km <= 0.1:
print(f"💥 DIRECTLY OVERHEAD: Orlan at {distance_km*1000:.0f}m altitude!")
else:
print(f"❌ Failed to send detection: {response.status_code}")
except Exception as e:
# Show escalation messages
if distance_km <= 5 and not critical_alerts_started:
print(f"🚨 CRITICAL ALERT: Orlan within {distance_km:.1f}km - AUTO-ESCALATED!")
critical_alerts_started = True
elif distance_km <= 1:
print(f"🔥 IMMEDIATE THREAT: Orlan within facility perimeter!")
elif distance_km <= 0.1:
print(f"💥 DIRECTLY OVERHEAD: Orlan at {distance_km*1000:.0f}m altitude!")
else:
print(f"❌ Failed to send Orlan detection at step {step}")
continue
print(f"❌ Error sending detection: {e}")
else:
# Outside detection range