feat: add QR code to enrollment screen for Traccar Client setup
Generate a QR code URL containing device ID, server URL, and update interval that the Traccar Client app can scan to auto-configure. The enrollment modal now shows the QR prominently with manual setup collapsed as a fallback. Also pins Traccar to 6.11 and fixes Docker health checks (IPv6/curl issues). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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<number>('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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user