{ "name": "MQTT Location Tracker - NocoDB", "nodes": [ { "parameters": { "topics": "owntracks/#", "options": {} }, "id": "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d", "name": "MQTT Trigger", "type": "n8n-nodes-base.mqttTrigger", "typeVersion": 1, "position": [ 80, 128 ], "credentials": { "mqtt": { "id": "MQTT_CREDENTIAL_ID", "name": "MQTT Broker" } } }, { "parameters": { "conditions": { "string": [ { "value1": "={{ $json._type }}", "value2": "location" } ] } }, "id": "b2c3d4e5-6f7a-8b9c-0d1e-2f3a4b5c6d7e", "name": "Ist Location?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 304, 128 ] }, { "parameters": { "jsCode": "// Extrahiere MQTT Location-Daten für NocoDB\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n const data = item.json;\n \n // Validiere erforderliche Felder\n if (!data.lat || !data.lon || !data.tst) {\n continue; // Überspringe ungültige Einträge\n }\n \n // Timestamp (tst = Unix timestamp in seconds)\n // Verwende tst oder fallback auf aktuelle Zeit\n const timestampMs = (data.tst && !isNaN(data.tst)) ? data.tst * 1000 : Date.now();\n const timestamp = new Date(timestampMs).toISOString();\n const displayTime = new Date(timestampMs).toLocaleString('de-DE');\n \n // Erstelle marker_label aus tid (tracker ID)\n const trackerLabel = data.tid || 'Unknown';\n \n // Optional: Verwende SSID als zusätzliche Info wenn vorhanden\n const markerLabel = data.SSID ? `${trackerLabel} (${data.SSID})` : trackerLabel;\n \n results.push({\n json: {\n latitude: data.lat,\n longitude: data.lon,\n timestamp: timestamp,\n user_id: 0, // MQTT hat keine User-ID, default auf 0\n first_name: trackerLabel,\n last_name: data.source || 'mqtt', // z.B. \"fused\"\n username: data.tid || '',\n marker_label: markerLabel,\n display_time: displayTime,\n chat_id: 0, // MQTT hat keine Chat-ID, default auf 0\n // Optional: Zusätzliche MQTT-Daten als Referenz\n mqtt_data: {\n accuracy: data.acc,\n altitude: data.alt,\n battery: data.batt,\n velocity: data.vel,\n course: data.cog,\n connection: data.conn,\n bssid: data.BSSID\n }\n }\n });\n}\n\nreturn results;" }, "id": "c3d4e5f6-7a8b-9c0d-1e2f-3a4b5c6d7e8f", "name": "MQTT Location verarbeiten", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 528, 112 ] }, { "parameters": { "authentication": "nocoDbApiToken", "operation": "create", "projectId": "pdxl4cx4dbu9nxi", "table": "m8pqj5ixgnnrzkg", "fieldsUi": { "fieldValues": [ { "fieldName": "latitude", "fieldValue": "={{ $json.latitude }}" }, { "fieldName": "longitude", "fieldValue": "={{ $json.longitude }}" }, { "fieldName": "timestamp", "fieldValue": "={{ $json.timestamp }}" }, { "fieldName": "user_id", "fieldValue": "={{ $json.user_id }}" }, { "fieldName": "first_name", "fieldValue": "={{ $json.first_name }}" }, { "fieldName": "last_name", "fieldValue": "={{ $json.last_name }}" }, { "fieldName": "username", "fieldValue": "={{ $json.username }}" }, { "fieldName": "marker_label", "fieldValue": "={{ $json.marker_label }}" }, { "fieldName": "display_time", "fieldValue": "={{ $json.display_time }}" }, { "fieldName": "chat_id", "fieldValue": "={{ $json.chat_id }}" } ] } }, "id": "d4e5f6a7-8b9c-0d1e-2f3a-4b5c6d7e8f9a", "name": "Speichere in NocoDB", "type": "n8n-nodes-base.nocoDb", "typeVersion": 2, "position": [ 752, 112 ], "credentials": { "nocoDbApiToken": { "id": "6fNBtcghMe8wFoE5", "name": "NocoDB Token account" } } }, { "parameters": { "height": 320, "width": 896, "color": 5 }, "type": "n8n-nodes-base.stickyNote", "position": [ 0, 0 ], "typeVersion": 1, "id": "e5f6a7b8-9c0d-1e2f-3a4b-5c6d7e8f9a0b", "name": "Sticky Note" } ], "pinData": {}, "connections": { "MQTT Trigger": { "main": [ [ { "node": "Ist Location?", "type": "main", "index": 0 } ] ] }, "Ist Location?": { "main": [ [ { "node": "MQTT Location verarbeiten", "type": "main", "index": 0 } ] ] }, "MQTT Location verarbeiten": { "main": [ [ { "node": "Speichere in NocoDB", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "mqtt-location-tracker-v1", "meta": { "instanceId": "12d864c68e4fb5dfd100dc0c683b95f43cd55af7e9efa82e25407fac5a3824a5" }, "id": "MqttLocationTracker01", "tags": [] }