74 lines
1.9 KiB
Bash
74 lines
1.9 KiB
Bash
#!/bin/bash
|
|
# Simple bash script to test drone detection API with curl
|
|
|
|
# Load environment variables from .env file if it exists
|
|
if [ -f ".env" ]; then
|
|
export $(grep -v '^#' .env | xargs)
|
|
fi
|
|
|
|
# Configuration from environment variables
|
|
API_BASE_URL=${API_BASE_URL:-"http://localhost:3002/api"}
|
|
BASE_PATH=${VITE_BASE_PATH:-""}
|
|
|
|
# If BASE_PATH is set, construct the full URL
|
|
if [ ! -z "$BASE_PATH" ] && [[ ! "$API_BASE_URL" == *"/api" ]]; then
|
|
# Remove any existing path suffixes and add base path
|
|
DOMAIN=$(echo "$API_BASE_URL" | sed 's|/api$||' | sed 's|/drones/api$||' | sed 's|/uggla/api$||')
|
|
API_BASE_URL="${DOMAIN}${BASE_PATH}/api"
|
|
fi
|
|
|
|
echo "🚁 Drone Detection API Test Script"
|
|
echo "=================================="
|
|
echo "🔗 Using API Base URL: $API_BASE_URL"
|
|
echo ""
|
|
|
|
# Test API health
|
|
echo "🔍 Testing API health..."
|
|
curl -s "$API_BASE_URL/health" | jq '.' || echo "Health check failed"
|
|
echo ""
|
|
|
|
# Send test detection data
|
|
echo "📡 Sending test drone detection..."
|
|
|
|
# Generate timestamp
|
|
TIMESTAMP=$(date +%s)000
|
|
|
|
# Test detection payload
|
|
DETECTION_DATA='{
|
|
"device_id": 1,
|
|
"drone_id": 1001,
|
|
"drone_type": 1,
|
|
"rssi": -65,
|
|
"freq": 2400,
|
|
"geo_lat": 59.3293,
|
|
"geo_lon": 18.0686,
|
|
"device_timestamp": '$TIMESTAMP',
|
|
"confidence_level": 0.85,
|
|
"signal_duration": 2500
|
|
}'
|
|
|
|
echo "Payload:"
|
|
echo "$DETECTION_DATA" | jq '.'
|
|
echo ""
|
|
|
|
# Send the detection
|
|
echo "Sending detection..."
|
|
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
|
|
-X POST "$API_BASE_URL/detectors" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$DETECTION_DATA")
|
|
|
|
# Parse response
|
|
HTTP_BODY=$(echo "$RESPONSE" | sed '$d')
|
|
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1 | sed 's/HTTP_STATUS://')
|
|
|
|
echo "Response Status: $HTTP_STATUS"
|
|
echo "Response Body:"
|
|
echo "$HTTP_BODY" | jq '.' 2>/dev/null || echo "$HTTP_BODY"
|
|
|
|
if [ "$HTTP_STATUS" = "201" ]; then
|
|
echo "✅ Detection sent successfully!"
|
|
else
|
|
echo "❌ Detection failed with status $HTTP_STATUS"
|
|
fi
|