close
本文章您将会学到如何透过 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? )
[gallery columns="1" size="full" ids="2480"]
- 打开 Container Station,选择您的iFrog Lora Gateway并点选 "终端机".
[gallery columns="1" size="full" ids="2481"]
- 输入命令:
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);"
[gallery columns="1" size="full" ids="2482"] - 新增字符串:-h : 填入QIoT Suite Lite 服务的IP (若QIoT Suite Lite与iFrogLab LoRa Gateway在同一台,请填入Container Station内建NAT的Gateway IP 预设为: 10.0.3.1)[gallery columns="1" size="full" ids="2493"]
-p : 预设21883,请依照resourceinfo.json信息进行填入
-t : (topic) 请依照resourceinfo.json信息进行填入
-u : (使用者名称) 请依照resourceinfo.json信息进行填入
-P : (密码) 请依照resourceinfo.json信息进行填入
-m : (讯息格式) 请依照范例填入即可
[gallery columns="1" size="full" ids="2494"]
- 输入命令:
- 按下 "Ctrl+O" 以及 "Enter" 保存并按下 "Crtl+X" 离开.
[gallery columns="1" size="full" ids="2488"] - 打开 "iFrogLora Gateway" 容器. 若出现以下画面即为修改成功
[gallery columns="1" size="full" ids="2489"]
- 按下 "Ctrl+O" 以及 "Enter" 保存并按下 "Crtl+X" 离开.
- 切换到 "QIoT Suite Lite" > "IoT 应用". 点选 " IoT 装置数据日志" 即可看见数据传入状态
[gallery columns="1" size="full" ids="2490"]
- 切换到 "QIoT Suite Lite" > "IoT 应用". 点选 " IoT 装置数据日志" 即可看见数据传入状态
- 切换到 "规则",即可开始设计您的IoT应用,接收到的数据为HEX。(可参考下列范例)
[gallery columns="1" size="full" ids="2491"]
- 切换到 "规则",即可开始设计您的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"
]
]
}
]
全站熱搜
留言列表