问题
I am new to Fiware and need help.
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.
How can I accomplish this task?
回答1:
We are a company that works with LwM2M protocol through FIWARE technologies, may be our IoT FIWARE Dockerized infrastructure could help you.
https://gitlab.hopu.eu/software/FIWARE/fiware-docker-infrastructure
回答2:
Reading your comments before, I understand that you want to build an scenario in order to connect your sensors to IotAgent-LWM2M.
In order to use LW2M2 IotAgent:
- 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
Technical Requirements:
- Mosquito MQTT v3.1 Broker
- Orion latest
- MongoDB v.3.2
- NodeJS v0.12
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"
Note: Mosquitto play a role like a sensor
Getting started: StepByStep
Step 1 : Create a device
(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
Step 2 : Create a service
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'
Step 3: connect your sensor to the client
(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]
Step 4: connect with the server
LWM2M-Client> connect localhost 5684 robot1 /
Step 5: Update attributes
set /7392/0 1 67
Step 6: Query to Orion to see updated attributes
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"
}
]
}
来源:https://stackoverflow.com/questions/52330498/setting-up-lwm2m-device-communicates-with-idas