Add battery and speed fields to tracker-db workflow

- Add battery and speed fields to Location processing node
- Add battery and speed fields to NocoDB storage
- Update API URL to home64.de domain
- Add new index_owntrack.html with battery/speed display

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-14 14:50:46 +00:00
parent 035148df2e
commit ea058828b8
3 changed files with 184 additions and 2 deletions

View File

@@ -82,7 +82,7 @@
}).addTo(map);
// API URL - anpassen an deine Domain
const API_URL = 'https://n8n.unixweb.eu/webhook/location';
const API_URL = 'https://n8n.unixweb.home64.de/webhook/location';
// Auto-Refresh State
let autoRefreshEnabled = true;

174
index_owntrack.html Normal file
View File

@@ -0,0 +1,174 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Location Test</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
#map { height: 100vh; width: 100%; }
.info {
position: absolute;
top: 10px;
right: 10px;
background: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
z-index: 1000;
min-width: 200px;
}
.toggle-btn {
margin-top: 15px;
padding: 10px 15px;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
width: 100%;
transition: all 0.3s ease;
font-size: 14px;
}
.toggle-btn.active {
background: #4CAF50;
color: white;
}
.toggle-btn.inactive {
background: #f44336;
color: white;
}
.toggle-btn:hover {
opacity: 0.8;
}
.status-indicator {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
margin-right: 6px;
}
.status-indicator.active {
background: #4CAF50;
animation: pulse 2s infinite;
}
.status-indicator.inactive {
background: #999;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
</style>
</head>
<body>
<div id="map"></div>
<div class="info">
<h3>📍 Location Tracker</h3>
<div id="status">Lade...</div>
<button id="toggleBtn" class="toggle-btn active" onclick="toggleAutoRefresh()">
<span class="status-indicator active"></span>
Auto-Refresh: AN
</button>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
// Karte initialisieren (München)
const map = L.map('map').setView([48.1351, 11.5820], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
}).addTo(map);
// API URL - anpassen an deine Domain
const API_URL = 'https://n8n.unixweb.home64.de/webhook/location';
// Auto-Refresh State
let autoRefreshEnabled = true;
let refreshInterval = null;
async function loadLocations() {
try {
const response = await fetch(API_URL);
const data = await response.json();
document.getElementById('status').innerHTML =
`Punkte: ${data.total_points || 0}<br>` +
`Status: ${data.success ? '✅ Verbunden' : '❌ Fehler'}`;
if (data.current) {
const loc = data.current;
// Popup-Inhalt aufbauen
let popupContent = `${loc.marker_label}<br>${loc.display_time}`;
// Batterie hinzufügen, falls vorhanden
if (loc.battery !== undefined && loc.battery !== null) {
popupContent += `<br>🔋 Batterie: ${loc.battery}%`;
}
// Geschwindigkeit hinzufügen, falls vorhanden
if (loc.velocity !== undefined && loc.velocity !== null) {
const speedKmh = (loc.velocity * 3.6).toFixed(1); // m/s zu km/h
popupContent += `<br>🚗 Speed: ${speedKmh} km/h`;
}
L.marker([loc.latitude, loc.longitude])
.addTo(map)
.bindPopup(popupContent)
.openPopup();
map.setView([loc.latitude, loc.longitude], 15);
// Historie als Linie
if (data.history && data.history.length > 1) {
const coords = data.history.map(h => [h.latitude, h.longitude]);
L.polyline(coords, {color: 'blue', weight: 3}).addTo(map);
}
}
} catch (error) {
document.getElementById('status').innerHTML = '❌ Verbindungsfehler';
console.error(error);
}
}
function toggleAutoRefresh() {
autoRefreshEnabled = !autoRefreshEnabled;
const btn = document.getElementById('toggleBtn');
const indicator = btn.querySelector('.status-indicator');
if (autoRefreshEnabled) {
// Aktiviere Auto-Refresh
btn.className = 'toggle-btn active';
btn.innerHTML = '<span class="status-indicator active"></span>Auto-Refresh: AN';
startAutoRefresh();
} else {
// Deaktiviere Auto-Refresh
btn.className = 'toggle-btn inactive';
btn.innerHTML = '<span class="status-indicator inactive"></span>Auto-Refresh: AUS';
stopAutoRefresh();
}
}
function startAutoRefresh() {
if (refreshInterval) clearInterval(refreshInterval);
refreshInterval = setInterval(loadLocations, 5000);
}
function stopAutoRefresh() {
if (refreshInterval) {
clearInterval(refreshInterval);
refreshInterval = null;
}
}
// Initial laden
loadLocations();
// Auto-refresh starten
startAutoRefresh();
</script>
</body>
</html>

View File

@@ -46,7 +46,7 @@
},
{
"parameters": {
"jsCode": "// Extrahiere Location-Daten für NocoDB\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n const location = item.json.message.location;\n const from = item.json.message.from;\n const messageDate = item.json.message.date;\n \n const timestamp = new Date(messageDate * 1000).toISOString();\n const displayTime = new Date(messageDate * 1000).toLocaleString('de-DE');\n \n results.push({\n json: {\n latitude: location.latitude,\n longitude: location.longitude,\n timestamp: timestamp,\n user_id: from.id,\n first_name: from.first_name || '',\n last_name: from.last_name || '',\n username: from.username || '',\n marker_label: `${from.first_name || ''} ${from.last_name || ''}`.trim(),\n display_time: displayTime,\n chat_id: item.json.message.chat.id\n }\n });\n}\n\nreturn results;"
"jsCode": "// Extrahiere Location-Daten für NocoDB\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n const location = item.json.message.location;\n const from = item.json.message.from;\n const messageDate = item.json.message.date;\n \n const timestamp = new Date(messageDate * 1000).toISOString();\n const displayTime = new Date(messageDate * 1000).toLocaleString('de-DE');\n \n results.push({\n json: {\n latitude: location.latitude,\n longitude: location.longitude,\n timestamp: timestamp,\n user_id: from.id,\n first_name: from.first_name || '',\n last_name: from.last_name || '',\n username: from.username || '',\n marker_label: `${from.first_name || ''} ${from.last_name || ''}`.trim(),\n display_time: displayTime,\n chat_id: item.json.message.chat.id,\n battery: null,\n speed: null\n }\n });\n}\n\nreturn results;"
},
"id": "648a42c5-99ce-4c7b-8a85-380cd40050d0",
"name": "Location verarbeiten",
@@ -104,6 +104,14 @@
{
"fieldName": "chat_id",
"fieldValue": "={{ $json.chat_id }}"
},
{
"fieldName": "battery",
"fieldValue": "={{ $json.battery }}"
},
{
"fieldName": "speed",
"fieldValue": "={{ $json.speed }}"
}
]
}