[
  {
    "id": "tab_edge_mqtt",
    "type": "tab",
    "label": "Edge MQTT 수신",
    "disabled": false,
    "info": "",
    "env": []
  },
  {
    "id": "n_mqtt_in",
    "type": "mqtt in",
    "z": "tab_edge_mqtt",
    "name": "/edge/point 구독",
    "topic": "/edge/point",
    "qos": "1",
    "datatype": "json",
    "broker": "cfg_edge_mqtt_broker",
    "nl": false,
    "rap": true,
    "rh": 0,
    "inputs": 0,
    "x": 150,
    "y": 80,
    "wires": [
      [
        "n_func_extract"
      ]
    ]
  },
  {
    "id": "n_func_extract",
    "type": "function",
    "z": "tab_edge_mqtt",
    "name": "태그/값 추출",
    "func": "var p = msg.payload;\nmsg.topic = p.tag_id || p.tag_name || p.tag || p.tagName || p.tagId || 'unknown';\nmsg.payload = {\n    tag:       p.tag_id || p.tag_name || p.tag || p.tagName || p.tagId,\n    value:     p.value,\n    timestamp: p.timestamp || p.ts,\n    edge_id:   p.edge_id || p.edgeId\n};\nreturn msg;",
    "outputs": 1,
    "timeout": 0,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 380,
    "y": 80,
    "wires": [
      [
        "n_debug_mqtt",
        "n_switch_alarm",
        "n_ws_out"
      ]
    ]
  },
  {
    "id": "n_debug_mqtt",
    "type": "debug",
    "z": "tab_edge_mqtt",
    "name": "수신 데이터",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": true,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "payload.value",
    "statusType": "auto",
    "x": 620,
    "y": 60,
    "wires": []
  },
  {
    "id": "n_switch_alarm",
    "type": "switch",
    "z": "tab_edge_mqtt",
    "name": "임계값 초과?",
    "property": "payload.value",
    "propertyType": "msg",
    "rules": [
      {
        "t": "gt",
        "v": "100",
        "vt": "num"
      }
    ],
    "checkall": "true",
    "repair": false,
    "outputs": 1,
    "x": 620,
    "y": 140,
    "wires": [
      [
        "n_debug_alarm"
      ]
    ]
  },
  {
    "id": "n_debug_alarm",
    "type": "debug",
    "z": "tab_edge_mqtt",
    "name": "⚠️ 임계값 초과 경보",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 860,
    "y": 140,
    "wires": []
  },
  {
    "id": "n_ws_out",
    "type": "websocket out",
    "z": "tab_edge_mqtt",
    "name": "WebSocket /ws/edge",
    "server": "cfg_ws_listener",
    "client": "",
    "x": 620,
    "y": 200,
    "wires": []
  },
  {
    "id": "cfg_edge_mqtt_broker",
    "type": "mqtt-broker",
    "name": "Edge MQTT (127.0.0.1:1883)",
    "broker": "127.0.0.1",
    "port": "1883",
    "clientid": "nodered-edge-client",
    "usetls": false,
    "compatmode": false,
    "keepalive": "60",
    "cleansession": true
  },
  {
    "id": "cfg_ws_listener",
    "type": "websocket-listener",
    "path": "/ws/edge",
    "wholemsg": "false"
  }
]
