如何在 QIoT Suite Lite 中透過 Modbus Gateway 與 Modbus 裝置連線?

如何在 QIoT Suite Lite 中透過 Modbus Gateway 與 Modbus 裝置連線?

本教學教你如何在 QIoT Suite Lite 中透過 Modbus Gateway (使用 WEP232 Modbus Gateway 示範) 與 Modbus 裝置連線,並以 AQD-101 四合一空氣品質顯示板 作為範例,安裝第三方 Node-red Plugin 支援 Modbus 協定裝置,使用的 Plugin 是 : node-red-contrib-modbus,請參考以下步驟安裝 Plugin :


安裝Node-red modbus plugin

  1. 使用 SSH 登入 NAS 後,執行以下命令 (參考: https://www.qnap.com/en/how-to/knowledge-base/article/how-to-access-qnap-nas-by-ssh):
    system-docker exec -ti qiot-node-red bash
  2. 切換至指定目錄
    cd /usr/local/lib/node_modules/node-red
  3. 安裝 node-red-contrib-modbus
    npm install node-red-contrib-modbus
  4. 重啟所有 Node-red
    supervisorctl restart all

 

Node-red modbus plugin 使用方式 (AQD-101 四合一空氣品質顯示板為範例)

  1. 請先參考下圖建立 Thing-Resource (參考 How to show DHT11 data on a QIoT Dashboard? 步驟1~5) :
  2. 參考以下範例,將範例 JSON 流程匯入到規則 (參考 : How to Backup QIoT Suite Lite ) :
    [
    {
    "id": "c01d41a4.a2fbc",
    "type": "tab",
    "label": "Flow 1"
    },
    {
    "id": "60f9272b.659558",
    "type": "modbus-client",
    "z": "",
    "name": "Air1",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "tcpHost": "192.168.110.100",
    "tcpPort": "502",
    "tcpType": "DEFAULT",
    "serialPort": "/dev/ttyUSB",
    "serialType": "RTU-BUFFERD",
    "serialBaudrate": "9600",
    "serialDatabits": "8",
    "serialStopbits": "1",
    "serialParity": "none",
    "serialConnectionDelay": "100",
    "unit_id": 1,
    "commandDelay": 1,
    "clientTimeout": 1000,
    "reconnectTimeout": 2000
    },
    {
    "id": "c37433a1.6ea7b",
    "type": "ui_base",
    "theme": {
    "name": "theme-light",
    "lightTheme": {
    "default": "#0094CE",
    "baseColor": "#0094CE",
    "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
    "edited": true,
    "reset": false
    },
    "darkTheme": {
    "default": "#097479",
    "baseColor": "#097479",
    "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
    "edited": false
    },
    "customTheme": {
    "name": "Untitled Theme 1",
    "default": "#4B7930",
    "baseColor": "#4B7930",
    "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
    },
    "themeState": {
    "base-color": {
    "default": "#0094CE",
    "value": "#0094CE",
    "edited": false
    },
    "page-titlebar-backgroundColor": {
    "value": "#0094CE",
    "edited": false
    },
    "page-backgroundColor": {
    "value": "#fafafa",
    "edited": false
    },
    "page-sidebar-backgroundColor": {
    "value": "#ffffff",
    "edited": false
    },
    "group-textColor": {
    "value": "#1bbfff",
    "edited": false
    },
    "group-borderColor": {
    "value": "#ffffff",
    "edited": false
    },
    "group-backgroundColor": {
    "value": "#ffffff",
    "edited": false
    },
    "widget-textColor": {
    "value": "#111111",
    "edited": false
    },
    "widget-backgroundColor": {
    "value": "#0094ce",
    "edited": false
    },
    "widget-borderColor": {
    "value": "#ffffff",
    "edited": false
    },
    "base-font": {
    "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
    }
    }
    },
    "site": {
    "name": "Node-RED Dashboard",
    "hideToolbar": "false",
    "allowSwipe": "false",
    "dateFormat": "DD/MM/YYYY",
    "sizes": {
    "sx": 48,
    "sy": 48,
    "gx": 6,
    "gy": 6,
    "cx": 6,
    "cy": 6,
    "px": 0,
    "py": 0
    }
    }
    },
    {
    "id": "e1e0707f.b407c",
    "type": "modbus-client",
    "z": "",
    "name": "gw",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "tcpHost": "192.168.0.100",
    "tcpPort": "502",
    "tcpType": "DEFAULT",
    "serialPort": "/dev/ttyUSB",
    "serialType": "RTU-BUFFERD",
    "serialBaudrate": "9600",
    "serialDatabits": "8",
    "serialStopbits": "1",
    "serialParity": "none",
    "serialConnectionDelay": "100",
    "unit_id": 1,
    "commandDelay": 1,
    "clientTimeout": 1000,
    "reconnectTimeout": 2000
    },
    {
    "id": "dfc2de90.d0679",
    "type": "ui_group",
    "z": "",
    "name": "QNAP",
    "tab": "9195395f.dd7be8",
    "disp": true,
    "width": "20"
    },
    {
    "id": "9195395f.dd7be8",
    "type": "ui_tab",
    "z": "",
    "name": "AQD101",
    "icon": "dashboard"
    },
    {
    "id": "5476a4bd.1d5a0c",
    "type": "modbus-response",
    "z": "c01d41a4.a2fbc",
    "name": "",
    "registerShowMax": 20,
    "x": 610,
    "y": 100,
    "wires": []
    },
    {
    "id": "9c555352.193fd",
    "type": "debug",
    "z": "c01d41a4.a2fbc",
    "name": "",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "false",
    "x": 290,
    "y": 260,
    "wires": []
    },
    {
    "id": "1794adc0.56e812",
    "type": "qiotbroker out",
    "z": "c01d41a4.a2fbc",
    "name": "temp",
    "opt_customtopic": false,
    "topic": "",
    "qos": "0",
    "retain": "false",
    "thing": "1eb4888a-254f-44be-a6c6-7a2c8a2019c1",
    "qtopic": "qiot/things/admin/air/temp",
    "username": "admin",
    "ver": "1",
    "x": 890,
    "y": 140,
    "wires": []
    },
    {
    "id": "d17c98b5.a8cad8",
    "type": "qiotbroker out",
    "z": "c01d41a4.a2fbc",
    "name": "hum",
    "opt_customtopic": false,
    "topic": "",
    "qos": "0",
    "retain": "false",
    "thing": "1eb4888a-254f-44be-a6c6-7a2c8a2019c1",
    "qtopic": "qiot/things/admin/air/co2",
    "username": "admin",
    "ver": "1",
    "x": 890,
    "y": 200,
    "wires": []
    },
    {
    "id": "c9ff0a1e.64b998",
    "type": "qiotbroker out",
    "z": "c01d41a4.a2fbc",
    "name": "co2",
    "opt_customtopic": false,
    "topic": "",
    "qos": "0",
    "retain": "false",
    "thing": "1eb4888a-254f-44be-a6c6-7a2c8a2019c1",
    "qtopic": "qiot/things/admin/air/co2",
    "username": "admin",
    "ver": "1",
    "x": 890,
    "y": 80,
    "wires": []
    },
    {
    "id": "3cf2b649.a55e6a",
    "type": "function",
    "z": "c01d41a4.a2fbc",
    "name": "AQD101",
    "func": "var myCO2=msg.payload[5];\nvar myPM25=msg.payload[6];\nvar myTemp=msg.payload[7]/100;\nvar myHumd=msg.payload[8]/100;\n/*\n//if (myTemp > 40) myTemp = 29.5;\n//if (myTemp < 10) myTemp = 29.5;\nvar oldTemp = global.get('Temp')||29.5;\nif (Math.abs(myTemp - oldTemp) > 1) myTemp = oldTemp;\n\nglobal.set('Temp', myTemp);\n*/\n\n/*\nmsg.payload.CO2 = myCO2;\nmsg.payload.Temp = myTemp;\nmsg.payload.Humd = myHumd;\nmsg.payload.PM25 = myPM25;\n*/\n\nvar CO2 = { payload:{value:myCO2}};\nvar Temp = { payload:{value:myTemp}};\nvar Humd = { payload:{value:myHumd}};\nvar PM25 = { payload:{value:myPM25}};\n\nreturn [CO2, Temp, Humd, PM25];\n//return msg;",
    "outputs": 4,
    "noerr": 0,
    "x": 580,
    "y": 180,
    "wires": [
    [
    "c9ff0a1e.64b998"
    ],
    [
    "1794adc0.56e812"
    ],
    [
    "d17c98b5.a8cad8"
    ],
    [
    "c08f0aaf.45a8d8"
    ]
    ],
    "outputLabels": [
    "CO2",
    "Temp",
    "Humd",
    "PM25"
    ]
    },
    {
    "id": "445c7656.277ba8",
    "type": "modbus-read",
    "z": "c01d41a4.a2fbc",
    "name": "",
    "topic": "",
    "showStatusActivities": false,
    "showErrors": false,
    "unitid": "1",
    "dataType": "InputRegister",
    "adr": "0",
    "quantity": "9",
    "rate": "1",
    "rateUnit": "s",
    "delayOnStart": false,
    "startDelayTime": "",
    "server": "60f9272b.659558",
    "x": 290,
    "y": 160,
    "wires": [
    [
    "5476a4bd.1d5a0c",
    "3cf2b649.a55e6a"
    ],
    [
    "9c555352.193fd"
    ]
    ]
    },
    {
    "id": "c08f0aaf.45a8d8",
    "type": "qiotbroker out",
    "z": "c01d41a4.a2fbc",
    "name": "pm2.5",
    "opt_customtopic": false,
    "topic": "",
    "qos": "0",
    "retain": "false",
    "thing": "1eb4888a-254f-44be-a6c6-7a2c8a2019c1",
    "qtopic": "qiot/things/admin/air/pm25",
    "username": "admin",
    "ver": "1",
    "x": 887,
    "y": 257,
    "wires": []
    }
    ]

     

  3. 匯入完成後請先變更 QBroker node,雙擊下圖紅色方框其中之一
  4. 進入設定介面後參見下圖選擇相應的 Thing 跟 Resource (例:co2 選 co2、temp 選 temp) 後點擊完成 (依序將其他的 QBroker node 做修改)
  5. 點擊  Modbus Read
    步驟 2 : 依據你的裝置操作手冊設定
    步驟 3 : 點擊  設定 Modbus Gateway IP
  6. 依據你的 Modbus Gateway IP、Port 進行設定,設定完畢後點擊 “更新” > “完成
  7. AQD101 Function node 可雙擊設定依據你裝置輸出的格式將程式碼進行調整
  8. 點擊 “儲存
  9. 參考 How to use the Dashboard after updating QIoT Suite Lite from v1.1.1 to v1.1.2? ,將 temphumco2pm25 加入到儀表板中,完成後如下圖:

Related posts