本文章您將會學到如何透過 iFrogLab LoRa 將訊息傳送到 QNAP QIoT Suite Lite.
事先準備
設定 iFrogLab LoRa USB 到 QIoT Suite Lite 以及 iFrogLab LoRa Gateway Container. 設定步驟請參考: http://www.ifroglab.com/en/?p=6613
(如果步驟10 一直沒出現裝置名稱,可能是 TTY 到USB 的模組尚未載入,請嘗試用 SSH 進入 NAS 並輸入下列命令:
insmod /usr/local/modules/cdc-acm.ko
insmod /usr/local/modules/cp210x.ko
insmod /usr/local/modules/ftdi_sio.ko )
如果NAS 重新開機,則需重新輸入以上命令。
設定 iFrogLab LoRa Gateway MQTT
請先建立 IoT 應用以及IoT 裝置,並取得json (請參考: 如何將 DHT11 溫濕度感測器的資料呈現在 QIoT 的 Dashboard? )
打開 Container Station,選擇您的iFrog Lora Gateway並點選 "終端機".
輸入命令:
nano /ifroglab/IL-LORA1272/LoRa-Gateway/Gateway/Python/ap-01-lora-gateway-2-read-httpGet.py"
並點選 "確認".
游標移動到下列指令
"mqtt=" mosquitto_pub -d -t ifroglab/mqtt -m '%s' -h test.mosquitto.org"%(HexString);"
並在前面加上 "#". 如下:
新增字串:
-h : 填入QIoT Suite Lite 服務的IP (若QIoT Suite Lite與iFrogLab LoRa Gateway在同一台,請填入Container Station內建NAT的Gateway IP 預設為: 10.0.3.1)
-p : 預設21883,請依照resourceinfo.json資訊進行填入
-t : (topic) 請依照resourceinfo.json資訊進行填入
-u : (使用者名稱) 請依照resourceinfo.json資訊進行填入
-P : (密碼) 請依照resourceinfo.json資訊進行填入
-m : (訊息格式) 請依照範例填入即可
按下 "Ctrl+O" 以及 "Enter" 保存並按下 "Crtl+X" 離開.
打開 "iFrogLora Gateway" 容器. 若出現以下畫面即為修改成功
切換到 "QIoT Suite Lite" > "IoT 應用". 點選 " IoT 裝置資料日誌" 即可看見資料傳入狀態
切換到 "規則",即可開始設計您的IoT應用,接收到的資料為HEX。(可參考下列範例)
範例:
[
{
"id": "e2bd8ea5.5c613",
"type": "debug",
"z": "8cc3c0a1.b6949",
"name": "Click debug tab to watch data stream",
"active": true,
"console": "false",
"complete": "false",
"x": 557.5,
"y": 92,
"wires": []
},
{
"id": "8ff255de.850808",
"type": "qiotbroker in",
"z": "8cc3c0a1.b6949",
"name": "MQTT Message In",
"flow": "8cc3c0a1.b6949",
"opt_customtopic": false,
"customtopic": "custom_topic_c13af1572d9611e8adc49f3a1551c296",
"thing": "ec626e0b-0524-4f06-9f8d-6c590730f7a9",
"qtopic": "qiot/things/admin/loradevice/data",
"username": "admin",
"rules": [
{
"v": "5ab347b29c31dc00322c43d0",
"meta": {
"unit": "°C",
"datatype": "String"
},
"resid": "data"
}
],
"outputs": 1,
"key": "r:5197487d0ab31b464c745aa7b8fa2616",
"x": 108.5,
"y": 43,
"wires": [
[
"d0d1710e.b9a8d"
]
]
},
{
"id": "d0d1710e.b9a8d",
"type": "change",
"z": "8cc3c0a1.b6949",
"name": "",
"rules": [
{
"t": "move",
"p": "payload.value",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 332,
"y": 43,
"wires": [
[
"1a8b6d9a.197722"
]
]
},
{
"id": "1a8b6d9a.197722",
"type": "function",
"z": "8cc3c0a1.b6949",
"name": "Decoded",
"func": "function convertFromHex(hex) {\n hex = hex.toString();//force conversion\n var str = '';\n for (var i = 1; i < hex.length + 1; i += 2)\n str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));\n return str;\n}\n\nmsg.payload = convertFromHex(msg.payload.substring(0, msg.payload.length - 4));\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 284,
"y": 92,
"wires": [
[
"e2bd8ea5.5c613"
]
]
}
]
更多教學文可以到QNAP QIoT Blog
https://qiot.qnap.com/blog/tw/
留言
張貼留言