Fixed gps
This commit is contained in:
@@ -12,8 +12,7 @@
|
||||
"description": "Dashboard",
|
||||
"dependencies": {
|
||||
"dotenv": "^17.4.1",
|
||||
"express": "^5.2.1",
|
||||
"node-gpsd": "^0.3.4"
|
||||
"express": "^5.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.10"
|
||||
|
||||
@@ -112,9 +112,9 @@ class DashboardHeader extends HTMLElement {
|
||||
if (gpsInfo && gpsDetail) {
|
||||
if (hasValidFix) {
|
||||
gpsInfo.textContent = `${gps.latitude.toFixed(4)}, ${gps.longitude.toFixed(4)}`;
|
||||
gpsDetail.textContent = `${gps.fix} • ${gps.satellites} sats • Alt: ${Math.round(gps.altitude)}m`;
|
||||
gpsDetail.textContent = `Alt: ${Math.round(gps.altitude)}m • Acc: ${Math.round(gps.accuracy)}m • ${gps.satellites} Sats`;
|
||||
} else {
|
||||
gpsInfo.textContent = gps.satellites > 0 ? 'Acquiring Fix...' : 'No Signal';
|
||||
gpsInfo.textContent = gps.satellites > 0 ? 'Acquiring Fix...' : 'No Fix';
|
||||
gpsDetail.textContent = `${gps.satellites} satellites`;
|
||||
}
|
||||
}
|
||||
@@ -956,8 +956,8 @@ class DashboardHeader extends HTMLElement {
|
||||
<div class="tile-name">GPS</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="tile-info">39.2000, -49.0000</div>
|
||||
<div class="tile-detail">No Fix</div>
|
||||
<div class="tile-info">No Fix</div>
|
||||
<div class="tile-detail">0 Satellites</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ import express from 'express';
|
||||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import { readFileSync, existsSync } from 'fs';
|
||||
import pkg from 'node-gpsd';
|
||||
const { GPS } = pkg;
|
||||
import {environment} from './environment.mjs';
|
||||
|
||||
const router = express.Router();
|
||||
@@ -15,43 +13,6 @@ let statusCache = null;
|
||||
let lastUpdate = 0;
|
||||
const CACHE_TTL = 15 * 1000; // 15 seconds
|
||||
|
||||
// GPS client setup
|
||||
let gpsClient = null;
|
||||
let gpsData = {
|
||||
fix: 'No Fix',
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
altitude: null,
|
||||
satellites: 0
|
||||
};
|
||||
|
||||
// Initialize GPS connection
|
||||
async function initGPS() {
|
||||
try {
|
||||
gpsClient = new GPS({ hostname: 'localhost', port: 2947 });
|
||||
|
||||
gpsClient.on('TPV', (data) => {
|
||||
gpsData.latitude = data.lat || null;
|
||||
gpsData.longitude = data.lon || null;
|
||||
gpsData.altitude = data.alt || null;
|
||||
gpsData.fix = data.mode === 3 ? '3D Fix' : data.mode === 2 ? '2D Fix' : 'No Fix';
|
||||
});
|
||||
|
||||
gpsClient.on('SKY', (data) => {
|
||||
gpsData.satellites = (data.satellites || []).length;
|
||||
});
|
||||
|
||||
gpsClient.on('error', (err) => {
|
||||
console.warn('GPS error:', err.message);
|
||||
});
|
||||
|
||||
await gpsClient.watch();
|
||||
console.log('GPS client initialized');
|
||||
} catch (error) {
|
||||
console.warn('GPS not available:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// CLI-based system information gathering
|
||||
async function getSystemInfo() {
|
||||
const info = {
|
||||
@@ -95,9 +56,11 @@ async function getSystemInfo() {
|
||||
async function getGPSInfo() {
|
||||
const gpsInfo = {
|
||||
satellites: 0,
|
||||
accuracy: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
altitude: null
|
||||
altitude: null,
|
||||
speed: null,
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -106,28 +69,23 @@ async function getGPSInfo() {
|
||||
|
||||
// Try to get GPS data using gpspipe
|
||||
const { stdout: gpsRaw } = await execAsync('timeout 3s gpspipe -w -n 5 | grep -E \'"class":"TPV"\' | head -1', { timeout: 4000 });
|
||||
|
||||
if (gpsRaw.trim()) {
|
||||
const gpsJson = JSON.parse(gpsRaw.trim());
|
||||
gpsInfo.latitude = gpsJson.lat || null;
|
||||
gpsInfo.longitude = gpsJson.lon || null;
|
||||
gpsInfo.altitude = gpsJson.alt || null;
|
||||
gpsInfo.satellites = +gpsJson.status || 0;
|
||||
gpsInfo.accuracy = +gpsJson.sep || null;
|
||||
gpsInfo.latitude = +gpsJson.lat || null;
|
||||
gpsInfo.longitude = +gpsJson.lon || null;
|
||||
gpsInfo.altitude = +gpsJson.alt || null;
|
||||
gpsInfo.speed = +gpsJson.speed || null;
|
||||
}
|
||||
|
||||
// Get satellite count
|
||||
try {
|
||||
const { stdout: skyRaw } = await execAsync('timeout 2s gpspipe -w -n 3 | grep -E \'"class":"SKY"\' | head -1', { timeout: 3000 });
|
||||
const { stdout: skyRaw } = await execAsync('timeout 2s gpspipe -w -n 3 | grep -E \'"class":"SKY"\' | head -1');
|
||||
if (skyRaw.trim()) {
|
||||
const skyJson = JSON.parse(skyRaw.trim());
|
||||
gpsInfo.satellites = (skyJson.satellites || []).length;
|
||||
}
|
||||
} catch (skyError) { }
|
||||
} catch (error) {
|
||||
console.warn('GPS info error:', error.message);
|
||||
// Use cached GPS data from node-gpsd if available
|
||||
if (gpsData.latitude !== null) {
|
||||
return gpsData;
|
||||
}
|
||||
}
|
||||
|
||||
return gpsInfo;
|
||||
@@ -332,11 +290,12 @@ async function generateStatus() {
|
||||
storage: systemInfo.storage
|
||||
},
|
||||
gps: {
|
||||
fix: gpsInfo.fix,
|
||||
satellites: gpsInfo.satellites,
|
||||
accuracy: gpsInfo.accuracy,
|
||||
latitude: gpsInfo.latitude,
|
||||
longitude: gpsInfo.longitude,
|
||||
altitude: gpsInfo.altitude
|
||||
altitude: gpsInfo.altitude,
|
||||
speed: gpsInfo.speed,
|
||||
},
|
||||
network: {
|
||||
wifi: networkInfo.wifi,
|
||||
@@ -420,7 +379,4 @@ router.get('/lora', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize GPS on startup
|
||||
initGPS().catch(err => console.warn('GPS initialization failed:', err.message));
|
||||
|
||||
export { router as statusRouter };
|
||||
|
||||
Reference in New Issue
Block a user