Setting up LWM2M device communicates with IDAS

房东的猫 提交于 2020-07-23 07:53:26

问题


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:

  1. Install LW2M2 agent: git clone https://github.com/telefonicaid/lightweightm2m-iotagent.git
  2. Install yarm to install all dependencies using npm packages
  3. Install Lightweight M2M client: git clone https://github.com/telefonicaid/lwm2m-node-lib.git

Technical Requirements:

  1. Mosquito MQTT v3.1 Broker
  2. Orion latest
  3. MongoDB v.3.2
  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!