{
  "name": "IoT Data Ingestion - Simple",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "iot-data-ingest",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-1",
      "name": "Webhook - Receive Data",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// Simple validation and processing\nconst data = $input.item.json;\n\n// Log the received data\nconsole.log('Received sensor data:', data);\n\n// Basic validation\nconst isValid = \n  data.device_id && \n  typeof data.temperature === 'number' && \n  typeof data.humidity === 'number';\n\n// Check thresholds\nconst tempOk = data.temperature >= 21 && data.temperature <= 24;\nconst humidityOk = data.humidity >= 40 && data.humidity <= 60;\n\nreturn {\n  json: {\n    ...data,\n    is_valid: isValid,\n    temp_status: tempOk ? 'normal' : 'alert',\n    humidity_status: humidityOk ? 'normal' : 'alert',\n    processed_at: new Date().toISOString()\n  }\n};"
      },
      "id": "function-1",
      "name": "Process Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:3001/webhook/reading",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {}
      },
      "id": "http-1",
      "name": "Send to WebSocket Bridge",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json.temp_status}}",
              "operation": "equals",
              "value2": "alert"
            }
          ]
        }
      },
      "id": "if-1",
      "name": "Temperature Alert?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        150
      ]
    },
    {
      "parameters": {
        "functionCode": "// Create alert\nconst data = $input.item.json;\n\nconst alert = {\n  alert_id: `alert-${Date.now()}`,\n  device_id: data.device_id,\n  parameter: 'temperature',\n  severity: data.temperature > 26 ? 'critical' : 'high',\n  current_value: data.temperature,\n  threshold_value: data.temperature > 24 ? 24 : 21,\n  message: `Temperature ${data.temperature > 24 ? 'above' : 'below'} threshold`,\n  timestamp: new Date().toISOString()\n};\n\nconsole.log('Alert created:', alert);\n\nreturn { json: alert };"
      },
      "id": "function-2",
      "name": "Create Alert",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        850,
        100
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:3001/webhook/alert",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {}
      },
      "id": "http-2",
      "name": "Send Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        1050,
        100
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"success\": true, \"device_id\": $json.device_id, \"timestamp\": $json.timestamp, \"status\": $json.temp_status } }}"
      },
      "id": "respond-1",
      "name": "Respond Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    }
  ],
  "connections": {
    "Webhook - Receive Data": {
      "main": [
        [
          {
            "node": "Process Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Data": {
      "main": [
        [
          {
            "node": "Send to WebSocket Bridge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Temperature Alert?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to WebSocket Bridge": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Temperature Alert?": {
      "main": [
        [
          {
            "node": "Create Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Alert": {
      "main": [
        [
          {
            "node": "Send Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2026-01-18T09:08:57.000Z",
  "versionId": "1"
}