设置LWM2M设备与IDAS通信 [英] Setting up LWM2M device communicates with IDAS
本文介绍了设置LWM2M设备与IDAS通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Fiware的新手,需要帮助.
I am new to Fiware and need help.
我想使用CoAP协议为IDAS IoT代理(轻量级M2M代理)配置路边设备(传感器),以便该设备可以向IDAS发送一些数据.
I want to configure a road side device (sensor) using CoAP protocol to the IDAS IoT agent (Lightweight M2M agent), so this device can send some data to IDAS.
我如何完成此任务?
推荐答案
在阅读您的评论之前,我了解到您想构建一个方案以将传感器连接到IotAgent-LWM2M.
Reading your comments before, I understand that you want to build an scenario in order to connect your sensors to IotAgent-LWM2M.
- 安装LW2M2代理:git clone https://github.com/telefonicaid/lightweightm2m-iotagent .git
- 安装yarm以使用npm软件包安装所有依赖项
- 安装轻型M2M客户端:git clone https://github.com/telefonicaid/lwm2m-node-lib.git
- Install LW2M2 agent: git clone https://github.com/telefonicaid/lightweightm2m-iotagent.git
- Install yarm to install all dependencies using npm packages
- Install Lightweight M2M client: git clone https://github.com/telefonicaid/lwm2m-node-lib.git
技术要求:
- Mosquito MQTT v3.1经纪人
- 猎户座最新
- MongoDB v.3.2
- NodeJS v0.12
我建议您使用docker在评论之前安装依赖项
I suggest you to use docker to install dependencies before comment
version : "2"
services:
mongo:
image: mongo:3.2
command: --nojournal
ports:
- "27017:27017"
expose:
- "27017"
orion:
image: fiware/orion
links:
- mongo
ports:
- "1026:1026"
command: -dbhost mongo
expose:
- "1026"
mosquitto:
image: ansi/mosquitto
ports:
- "1883:1883"
expose:
- "1883"
注意: 蚊子扮演着类似传感器的角色
(curl localhost:4041/iot/devices -s -S --header 'Content-Type: application/json' \
--header 'Accept: application/json' --header 'fiware-service: Factory' --header 'fiware-servicepath: /robots' \
-d @- | python -mjson.tool) <<EOF
{
"devices": [
{
"device_id": "robot1",
"entity_type": "Robot",
"attributes": [
{
"name": "Battery",
"type": "number"
}
],
"lazy": [
{
"name": "Message",
"type": "string"
}
],
"commands": [
{
"name": "Position",
"type": "location"
}
],
"internal_attributes": {
"lwm2mResourceMapping": {
"Battery" : {
"objectType": 7392,
"objectInstance": 0,
"objectResource": 1
},
"Message" : {
"objectType": 7392,
"objectInstance": 0,
"objectResource": 2
},
"Position" : {
"objectType": 7392,
"objectInstance": 0,
"objectResource": 3
}
}
}
}]}
EOF
第2步:创建服务
curl -X POST -H "Fiware-Service: myHome" -H "Fiware-ServicePath: /environment" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"services": [
{
"resource": "/",
"apikey": "",
"type": "Robot",
"cbroker":"localhost:1026"
}]
}' 'http://localhost:4041/iot/services'
步骤3:将传感器连接到客户端
(bin/iotagent-lwm2m-client.js)
Object Creation:
LWM2M-Client> create /7392/0
Battery attribute:
LWM2M-Client> set /7392/0 1 89
Message Attribute:
LWM2M-Client> set /7392/0 2 "First robot here"
Position attribute:
LWM2M-Client> set /7392/0 3 "[0,0]
步骤4:与服务器连接
LWM2M-Client> connect localhost 5684 robot1 /
第5步:更新属性
set /7392/0 1 67
第6步:查询Orion以查看更新的属性
curl -X POST http://localhost:1026/v1/queryContext -s -S
--header 'Content-Type: application/json' \
--header 'Accept: application/json' --header 'fiware-service: Factory'
--header 'fiware-servicepath: /robots' \
-d '
{
"entities": [
{
"type": "Robot",
"isPattern": "false",
"id": "Robot:robot1"
}
]
}
这篇关于设置LWM2M设备与IDAS通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文