pump / node-red /README.md
Codex
Deploy efficiency estimate fix cf55248
aec7019
|
Raw History Blame Contribute Delete
4.25 kB

Node-RED OPC 采集层

独立于力控的 OPC UA 采集层。用 node-red-contrib-opcua 直连现场 PLC / OPC UA Server, 整形为统一 JSON 快照后经 REST + WebSocket 发布,供 frontend/index.html 展示页消费。 不使用力控任何原生 OPC 能力(不启用 PCAuto.OPCServer、不用力控 OPCUA CLIENT 驱动)。

PLC / OPC UA Server ──OPC UA──▶ Node-RED(node-red-contrib-opcua)
                                    │ 整形统一快照(flow.snapshot)
                                    ├─ WebSocket  /ws/realtime  (每秒推送)
                                    └─ REST(GET)  /api/realtime (最新快照, 含 CORS)
                                          ▼
                                frontend/index.html (ECharts) ──嵌入──▶ 力控 FWebView

安装

npm install -g node-red            # 如未安装 Node-RED
cd ~/.node-red && npm install node-red-contrib-opcua@0.2.354
node-red                           # 默认 http://localhost:1880

离线工控机:在有网机器 npm pack node-red-contrib-opcua 生成 tgz,拷入后 cd ~/.node-red && npm install ./node-red-contrib-opcua-*.tgz。

配置中心驱动的通用 flow

Docker Compose 默认加载 flows-configurable.json。手工部署时可在 Node-RED 右上角菜单 → 导入 → 选择该文件 → 部署(Deploy)。

通用 flow 包含四部分:

  1. 配置同步 — 每 10 秒读取 FastAPI /api/integration/runtime,保存后自动生效。
  2. 动态 OPC UA 采集 — 端点、安全策略、账号、采样周期和 NodeId 都来自配置中心。
  3. 仿真数据 — 后台选择“仿真数据”时自动启用,不再人工禁用/启用节点。
  4. 统一发布 — 标准快照同时发布到 /ws/realtime 和 GET /api/realtime。

旧版 flows.json 保留作历史参考,新部署统一使用 flows-configurable.json。

端到端跑通(连仿真服务器)

拓扑:标准PC(OPC UA Server) ──OPC UA──▶ Node-RED(readmultiple) ──WS/REST──▶ HTML 展示页。 本仓用仿真服务器代替现场标准 PC 即可端到端演示:

# 1) 起 OPC UA 仿真服务器(把泵站点位模拟出来)
cd backend && python -m app.opcua_sim_server        # opc.tcp://0.0.0.0:4840/biditech/server/

# 2) Node-RED:启用分支③各节点(右键 Enable),禁用①的 sim_tick,Deploy
# 3) curl http://localhost:1880/api/realtime  → 应返回来自 OPC 的快照
# 4) 打开 frontend/index.html → 数据来自 Node-RED←OPC UA

切换到现场标准 PC

  1. 双击 OpcUa-Endpoint:把端点改成现场标准 PC 的 OPC UA 服务器地址 (端口用 UaExpert 实测,勿假设 4840);安全策略先 None 打通、上线切 Basic256Sha256 + Sign&Encrypt。
  2. 用 UaExpert 浏览确认命名空间索引 ns(仿真服务器默认 ns=2)与点位命名, 若不同则改 构建 NodeId 列表 函数里的 NS 与名称(对齐文档 4.1:ns=<idx>;s=PumpStation1.<...>)。
  3. 启用分支③、禁用①的 1s tick,Deploy。OPC→统一快照 按序整形进 flow.snapshot,复用同一套 REST/WS 发布。

字段约定(与展示页一致):

{
  "station": "海斯特污水提升泵站",
  "level": 5.5, "pressure": 0.14, "head": 14.5,
  "totalFlow": 1620, "totalPower": 84.5, "sec": 0.052,
  "pumps": [
    { "id": 1, "freq": 49.0, "current": 88.0, "power": 52.0,
      "status": 1, "flow": 820, "head": 14.6, "runHours": 4700, "sec": 0.063 }
  ],
  "ts": 1751457600000
}

status: 0=停止, 1=运行, 2=故障。

验证

curl http://localhost:1880/api/realtime      # 应返回 JSON 快照

展示页 frontend/index.html 默认连 ws://<本机>:1880/ws/realtime,连上后右上角状态变 「已连接 · OPC 实时」;连不上自动降级为内置仿真(黄色「仿真数据」)。数据源地址在 index.html 顶部 CONFIG 常量中修改。

嵌入力控

力控画面添加 FWebView / HTML5 浏览器控件,URL 指向部署好的 frontend/index.html(同网段静态 Web 或 Node-RED 静态目录)。力控仅作展示宿主, 不做数据点绑定。