diff --git a/backend/src/gps/gps.service.ts b/backend/src/gps/gps.service.ts index e689b3e..3fb13b2 100644 --- a/backend/src/gps/gps.service.ts +++ b/backend/src/gps/gps.service.ts @@ -5,6 +5,7 @@ import { BadRequestException, OnModuleInit, } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { Cron, CronExpression } from '@nestjs/schedule'; import { PrismaService } from '../prisma/prisma.service'; import { SignalService } from '../signal/signal.service'; @@ -27,6 +28,7 @@ export class GpsService implements OnModuleInit { private prisma: PrismaService, private traccarClient: TraccarClientService, private signalService: SignalService, + private configService: ConfigService, ) {} async onModuleInit() { @@ -141,6 +143,7 @@ export class GpsService implements OnModuleInit { success: boolean; deviceIdentifier: string; serverUrl: string; + qrCodeUrl: string; instructions: string; signalMessageSent?: boolean; }> { @@ -192,6 +195,19 @@ export class GpsService implements OnModuleInit { const serverUrl = this.traccarClient.getDeviceServerUrl(); const settings = await this.getSettings(); + // Build QR code URL for Traccar Client app + // Format: https://server:5055?id=DEVICE_ID&interval=SECONDS + // The Traccar Client app parses this as: server URL (origin) + query params (id, interval, etc.) + const devicePort = this.configService.get('TRACCAR_DEVICE_PORT') || 5055; + const traccarPublicUrl = this.traccarClient.getTraccarUrl(); + const qrUrl = new URL(traccarPublicUrl); + qrUrl.port = String(devicePort); + qrUrl.searchParams.set('id', actualDeviceId); + qrUrl.searchParams.set('interval', String(settings.updateIntervalSeconds)); + const qrCodeUrl = qrUrl.toString(); + + this.logger.log(`QR code URL for driver: ${qrCodeUrl}`); + const instructions = ` GPS Tracking Setup Instructions for ${driver.name}: @@ -234,6 +250,7 @@ Note: GPS tracking is only active during shift hours (${settings.shiftStartHour} success: true, deviceIdentifier: actualDeviceId, // Return what Traccar actually stored serverUrl, + qrCodeUrl, instructions, signalMessageSent, }; diff --git a/docker-compose.yml b/docker-compose.yml index 10f20c3..1b61be2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,7 +52,7 @@ services: # Traccar GPS Tracking Server traccar: - image: traccar/traccar:latest + image: traccar/traccar:6.11 container_name: vip-traccar ports: - "8082:8082" # Web UI & API diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 430d0d1..5ad11e4 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -46,7 +46,7 @@ EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost/ || exit 1 + CMD wget --no-verbose --tries=1 --spider http://127.0.0.1/ || exit 1 # Start nginx CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/src/pages/GpsTracking.tsx b/frontend/src/pages/GpsTracking.tsx index 9767d7f..300130d 100644 --- a/frontend/src/pages/GpsTracking.tsx +++ b/frontend/src/pages/GpsTracking.tsx @@ -768,18 +768,37 @@ export function GpsTracking() { )} - {/* Manual Configuration - Traccar Client doesn't reliably scan QR codes */} -
-
- + {/* QR Code - scan with Traccar Client app to auto-configure */} +
+
+ + Scan with Traccar Client +
+
+ +
+

+ Open Traccar Client app → tap the QR icon → scan this code +

+
+ + {/* Download links */} +
+
+ Download Traccar Client
-
+
iOS App Store @@ -787,56 +806,54 @@ export function GpsTracking() { href="https://play.google.com/store/apps/details?id=org.traccar.client" target="_blank" rel="noopener noreferrer" - className="px-3 py-1 bg-green-600 text-white text-sm rounded hover:bg-green-700" + className="px-3 py-1 bg-green-600 text-white text-xs rounded hover:bg-green-700" > Google Play
-

- Must use official Traccar Client app (not other GPS apps) -

-
-
- -
- - {enrollmentResult.deviceIdentifier} - - + {/* Manual fallback - collapsible */} +
+ + Manual Setup (if QR doesn't work) + +
+
+ +
+ + {enrollmentResult.deviceIdentifier} + + +
-
-
- -
- - {enrollmentResult.serverUrl} - - +
+ +
+ + {enrollmentResult.serverUrl} + + +
+
    +
  1. Open Traccar Client and enter Device ID and Server URL above
  2. +
  3. Set frequency to {settings?.updateIntervalSeconds || 60} seconds
  4. +
  5. Tap "Service Status" to start tracking
  6. +
-
- -
-

Driver Instructions:

-
    -
  1. Download "Traccar Client" from App Store or Play Store
  2. -
  3. Open app and enter the Device ID and Server URL
  4. -
  5. Set frequency to {settings?.updateIntervalSeconds || 60} seconds
  6. -
  7. Tap "Service Status" to start tracking
  8. -
-
+