diff --git a/.env.example b/.env.example index 3056eb9..d3e1525 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ # Web environment (Vite) -VITE_SUPABASE_URL=http://127.0.0.1:54321 +VITE_SUPABASE_URL=http://localhost:54321 VITE_SUPABASE_ANON_KEY=[REDACTED] # API config (optional) diff --git a/camera-management-api/Dockerfile b/camera-management-api/Dockerfile index 72395cb..5b36c69 100644 --- a/camera-management-api/Dockerfile +++ b/camera-management-api/Dockerfile @@ -3,23 +3,17 @@ FROM python:3.11-slim # Install system dependencies required by SDK and tooling RUN apt-get update && apt-get install -y --no-install-recommends \ - bash ca-certificates tar \ + bash ca-certificates tar sudo \ libusb-1.0-0 libgl1 libx11-6 libxext6 libxcb1 libgtk-3-0 \ + libusb-1.0-0-dev udev \ && rm -rf /var/lib/apt/lists/* -# Copy SDK bundle placed under api/camera_sdk and install native libs +# Set working directory WORKDIR /app -COPY camera_sdk /tmp/camera_sdk -RUN set -eux; \ - mkdir -p /opt/mvsdk; \ - TARBALL="$(find /tmp/camera_sdk -maxdepth 1 -type f -name '*.tar.gz' | head -n1)"; \ - if [ -z "$TARBALL" ]; then echo 'No SDK .tar.gz found in camera_sdk'; exit 1; fi; \ - tar -xzf "$TARBALL" -C /opt/mvsdk || true; \ - # Copy any .so library files into /usr/lib so ctypes can load libMVSDK.so - find /opt/mvsdk -type f -name '*.so*' -exec cp -n {} /usr/lib/ \; || true; \ - ldconfig || true +# Set environment variables for library paths and Python path +ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:/lib +ENV PYTHONPATH=/app:/app/camera_sdk -ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/lib - -# The actual app code is bind-mounted by docker-compose at runtime +# The actual app code and SDK will be bind-mounted by docker-compose at runtime +# SDK installation will be handled in the docker-compose command diff --git a/camera-management-api/check_time.py b/camera-management-api/check_time.py new file mode 100755 index 0000000..a8ee0c5 --- /dev/null +++ b/camera-management-api/check_time.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +""" +Time verification script for USDA Vision Camera System +Checks if system time is properly synchronized +""" + +import datetime +import pytz +import requests +import json + +def check_system_time(): + """Check system time against multiple sources""" + print("๐Ÿ• USDA Vision Camera System - Time Verification") + print("=" * 50) + + # Get local time + local_time = datetime.datetime.now() + utc_time = datetime.datetime.utcnow() + + # Get Atlanta timezone + atlanta_tz = pytz.timezone('America/New_York') + atlanta_time = datetime.datetime.now(atlanta_tz) + + print(f"Local system time: {local_time}") + print(f"UTC time: {utc_time}") + print(f"Atlanta time: {atlanta_time}") + print(f"Timezone: {atlanta_time.tzname()}") + + # Check against world time API + try: + print("\n๐ŸŒ Checking against world time API...") + response = requests.get("http://worldtimeapi.org/api/timezone/America/New_York", timeout=5) + if response.status_code == 200: + data = response.json() + api_time = datetime.datetime.fromisoformat(data['datetime'].replace('Z', '+00:00')) + + # Compare times (allow 5 second difference) + time_diff = abs((atlanta_time.replace(tzinfo=None) - api_time.replace(tzinfo=None)).total_seconds()) + + print(f"API time: {api_time}") + print(f"Time difference: {time_diff:.2f} seconds") + + if time_diff < 5: + print("โœ… Time is synchronized (within 5 seconds)") + return True + else: + print("โŒ Time is NOT synchronized (difference > 5 seconds)") + return False + else: + print("โš ๏ธ Could not reach time API") + return None + except Exception as e: + print(f"โš ๏ธ Error checking time API: {e}") + return None + +if __name__ == "__main__": + check_system_time() diff --git a/camera-management-api/config.compose.json b/camera-management-api/config.compose.json index b165d1f..4f258b4 100644 --- a/camera-management-api/config.compose.json +++ b/camera-management-api/config.compose.json @@ -1,6 +1,6 @@ { "mqtt": { - "broker_host": "mqtt", + "broker_host": "192.168.1.110", "broker_port": 1883, "username": null, "password": null, @@ -89,5 +89,4 @@ "hdr_gain_mode": 0 } ] -} - +} \ No newline at end of file diff --git a/camera-management-api/start_system.sh b/camera-management-api/start_system.sh index db61d06..ecd7f9f 100755 --- a/camera-management-api/start_system.sh +++ b/camera-management-api/start_system.sh @@ -4,6 +4,11 @@ echo "USDA Vision Camera System - Startup Script" echo "==========================================" +# Ensure we are running from the script directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" +echo "๐Ÿ“‚ Working directory: $SCRIPT_DIR" + # Check if virtual environment exists if [ ! -d ".venv" ]; then @@ -14,6 +19,9 @@ fi # Activate virtual environment echo "๐Ÿ”ง Activating virtual environment..." source .venv/bin/activate +# Ensure project root is on PYTHONPATH for imports +export PYTHONPATH="$SCRIPT_DIR:$PYTHONPATH" + # Check if config file exists if [ ! -f "config.json" ]; then @@ -30,11 +38,11 @@ fi # Check time synchronization echo "๐Ÿ• Checking time synchronization..." -python check_time.py +python tests/core/check_time.py echo "" # Run system tests first echo "๐Ÿงช Running system tests..." -python test_system.py +python tests/integration/test_system.py if [ $? -ne 0 ]; then echo "โŒ System tests failed. Please check the configuration." diff --git a/docker-compose.yml b/docker-compose.yml index f27ae60..df2be03 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,18 +11,36 @@ services: - ./camera-management-api/storage:/storage environment: - PYTHONUNBUFFERED=1 - - LD_LIBRARY_PATH=/usr/local/lib:/app/camera_sdk/lib + - LD_LIBRARY_PATH=/usr/local/lib:/lib:/usr/lib + - PYTHONPATH=/app:/app/camera_sdk command: > sh -lc " apt-get update && apt-get install -y libusb-1.0-0-dev; - if [ -d camera_sdk/lib ]; then cp camera_sdk/lib/* /usr/local/lib/ 2>/dev/null || true; fi; - if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; else pip install --no-cache-dir -e .; fi; + + # Install camera SDK if not already installed + if [ ! -f /lib/libMVSDK.so ] && [ -f 'camera_sdk/linuxSDK_V2.1.0.49(250108)/install.sh' ]; then + echo 'Installing camera SDK...'; + cd 'camera_sdk/linuxSDK_V2.1.0.49(250108)'; + chmod +x install.sh; + ./install.sh; + cd /app; + echo 'Camera SDK installed successfully'; + else + echo 'Camera SDK already installed or install script not found'; + fi; + + # Install Python dependencies + if [ -f requirements.txt ]; then + pip install --no-cache-dir -r requirements.txt; + else + pip install --no-cache-dir -e .; + fi; + + # Start the application python main.py --config config.compose.json " ports: - "8000:8000" - depends_on: - - mqtt web: image: node:20-alpine @@ -36,19 +54,9 @@ services: command: > sh -lc " npm ci; - npm run dev -- --host 0.0.0.0 --port 5173 + npm run dev -- --host 0.0.0.0 --port 8080 " ports: - - "5173:5173" + - "8080:8080" - mqtt: - image: eclipse-mosquitto:2 - ports: - - "1883:1883" - volumes: - - mosquitto-data:/mosquitto/data - - mosquitto-conf:/mosquitto/config -volumes: - mosquitto-data: - mosquitto-conf: diff --git a/management-dashboard-web-app/vite.config.ts b/management-dashboard-web-app/vite.config.ts index 8855614..ed12bb0 100644 --- a/management-dashboard-web-app/vite.config.ts +++ b/management-dashboard-web-app/vite.config.ts @@ -4,7 +4,14 @@ import tailwindcss from '@tailwindcss/vite' // https://vite.dev/config/ export default defineConfig({ - plugins: [react(), - tailwindcss(), + plugins: [ + react(), + tailwindcss(), ], + server: { + // Allow connecting via this VM's hostname + allowedHosts: ['exp-dash'], + // host is provided via CLI in docker-compose, but keeping this commented for local use: + // host: true, + }, })