IoT Agent for JSON

IoT Agent for JSON の健全性チェック

IoT Agent for JSON が起動したら、次のコマンドでステータスを確認できます:

リクエスト:

ngsi version --host iotagent-json.local --pretty

レスポンス:

{
  "libVersion": "4.4.0",
  "port": "4041",
  "baseRoot": "/",
  "version": "3.4.0"
}

IoT Agent for JSON over MQTT

サービスの作成

リクエスト:

ngsi services \
  --host iotagent-json.local \
  create \
  --apikey  SMoCnNjlrAfeFOtlaC8XAhM8o1 \
  --type Thing \
  --resource /iot/json \
   --cbroker http://orion:1026

サービスの一覧表示

リクエスト:

ngsi services \
  --host iotagent-json.local \
  list \
  --pretty

レスポンス:

{
  "count": 1,
  "services": [
    {
      "commands": [],
      "lazy": [],
      "attributes": [],
      "_id": "618e271d12b5ce10113cb4b8",
      "resource": "/iot/json",
      "apikey": "SMoCnNjlrAfeFOtlaC8XAhM8o1",
      "service": "openiot",
      "subservice": "/",
      "__v": 0,
      "static_attributes": [],
      "internal_attributes": [],
      "entity_type": "Thing"
    }
  ]
}

デバイスの作成

リクエスト:

ngsi devices \
  --host iotagent-json.local \
  create \
  --data '{ \
  "devices": [
    {
      "device_id":   "sensor002",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor002",
      "entity_type": "Sensor",
      "timezone":    "Asia/Tokyo",
      "transport":   "MQTT",
      "attributes": [
        { "object_id": "d", "name": "dateObserved", "type": "DateTime" },
        { "object_id": "t", "name": "temperature", "type": "Number" },
        { "object_id": "h", "name": "relativeHumidity", "type": "Number" },
        { "object_id": "p", "name": "atmosphericPressure", "type": "Number" }
      ],
      "static_attributes": [
        { "name":"location", "type": "geo:json", "value" : { "type": "Point", "coordinates" : [ 139.7671, 35.68117 ] } }
      ]
    }
  ]
}'

デバイスの一覧表示

リクエスト:

ngsi devices \
  --host iotagent-json.local \
  list \
  --pretty

レスポンス:

{
  "count": 1,
  "devices": [
    {
      "device_id": "sensor002",
      "service": "openiot",
      "service_path": "/",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor002",
      "entity_type": "Sensor",
      "transport": "MQTT",
      "attributes": [
        {
          "object_id": "d",
          "name": "dateObserved",
          "type": "DateTime"
        },
        {
          "object_id": "t",
          "name": "temperature",
          "type": "Number"
        },
        {
          "object_id": "h",
          "name": "relativeHumidity",
          "type": "Number"
        },
        {
          "object_id": "p",
          "name": "atmosphericPressure",
          "type": "Number"
        }
      ],
      "lazy": [],
      "commands": [],
      "static_attributes": [
        {
          "name": "location",
          "type": "geo:json",
          "value": {
            "type": "Point",
            "coordinates": [
              139.7671,
              35.68117
            ]
          }
        }
      ],
      "explicitAttrs": false
    }
  ]
}

データの送信

リクエスト:

mosquitto_pub \
  --debug \
  --host mosquitto.local
  --port 8883 \
  --username fiware --pw cDQB6DsIy5TFSdjy \
  --topic "/SMoCnNjlrAfeFOtlaC8XAhM8o1/sensor002/attrs" \
  --message '{"d":"2021-11-12T08:37:44+0000","t":9327,"h":3064,"p":27652}' \
  --cafile ./config/mosquitto/isrgrootx1.pem

エンティティの表示

リクエスト:

ngsi get \
  --host orion.local \
  --service openiot \
  --path / \
  entity \
  --id urn:ngsi-ld:WeatherObserved:sensor00 \
  --pretty

レスポンス:

{
  "id": "urn:ngsi-ld:WeatherObserved:sensor002",
  "type": "Sensor",
  "TimeInstant": {
    "type": "DateTime",
    "value": "2021-11-12T08:37:44.668Z",
    "metadata": {}
  },
  "atmosphericPressure": {
    "type": "Number",
    "value": 27652,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:37:44.668Z"
      }
    }
  },
  "dateObserved": {
    "type": "DateTime",
    "value": "2021-11-12T08:37:44.000Z",
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:37:44.668Z"
      }
    }
  },
  "location": {
    "type": "geo:json",
    "value": {
      "type": "Point",
      "coordinates": [
        139.7671,
        35.68117
      ]
    },
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:37:44.668Z"
      }
    }
  },
  "relativeHumidity": {
    "type": "Number",
    "value": 3064,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:37:44.668Z"
      }
    }
  },
  "temperature": {
    "type": "Number",
    "value": 9327,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:37:44.668Z"
      }
    }
  }
}

こちらの例を参照ください。

IoT Agent for JSON over HTTP

サービスの作成

リクエスト:

ngsi services \
  --host iotagent-json.local \
  create \
  --apikey XaEMQ86tTBHCwN0C9MjiHXcYFX \
  --type Thing \
  --resource /iot/json \
  --cbroker http://orion:1026

サービスの一覧表示

リクエスト:

ngsi services \
  --host iotagent-json.local \
  list \
  --pretty

レスポンス:

{
  "count": 1,
  "services": [
    {
      "commands": [],
      "lazy": [],
      "attributes": [],
      "_id": "618e296133b2b1c5e3ddfa89",
      "resource": "/iot/json",
      "apikey": "XaEMQ86tTBHCwN0C9MjiHXcYFX",
      "service": "openiot",
      "subservice": "/",
      "__v": 0,
      "static_attributes": [],
      "internal_attributes": [],
      "entity_type": "Thing"
    }
  ]
}

デバイスの作成

リクエスト:

ngsi devices \
  --host iotagent-json.local \
  create \
  --data '{
  "devices": [
    {
      "device_id":   "sensor004",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor004",
      "entity_type": "Sensor",
      "timezone":    "Asia/Tokyo",
      "attributes": [
        { "object_id": "d", "name": "dateObserved", "type": "DateTime" },
        { "object_id": "t", "name": "temperature", "type": "Number" },
        { "object_id": "h", "name": "relativeHumidity", "type": "Number" },
        { "object_id": "p", "name": "atmosphericPressure", "type": "Number" }
      ],
      "static_attributes": [
        { "name":"location", "type": "geo:json", "value" : { "type": "Point", "coordinates" : [ 139.7671, 35.68117 ] } }
      ]
    }
  ]
}'

デバイスの一覧表示

リクエスト:

ngsi devices \
  --host iotagent-json.local \
  list \
  --pretty

レスポンス:

{
  "count": 1,
  "devices": [
    {
      "device_id": "sensor004",
      "service": "openiot",
      "service_path": "/",
      "entity_name": "urn:ngsi-ld:WeatherObserved:sensor004",
      "entity_type": "Sensor",
      "transport": "HTTP",
      "attributes": [
        {
          "object_id": "d",
          "name": "dateObserved",
          "type": "DateTime"
        },
        {
          "object_id": "t",
          "name": "temperature",
          "type": "Number"
        },
        {
          "object_id": "h",
          "name": "relativeHumidity",
          "type": "Number"
        },
        {
          "object_id": "p",
          "name": "atmosphericPressure",
          "type": "Number"
        }
      ],
      "lazy": [],
      "commands": [],
      "static_attributes": [
        {
          "name": "location",
          "type": "geo:json",
          "value": {
            "type": "Point",
            "coordinates": [
              139.7671,
              35.68117
            ]
          }
        }
      ],
      "explicitAttrs": false
    }
  ]
}

データの送信

リクエスト:

 curl -X POST "https://iotagent-http.local/iot/ul?k=XaEMQ86tTBHCwN0C9MjiHXcYFX&i=sensor004" \
   -u "fiware:1HAmMeajDpPSuTaF" \
   -H "Content-Type: text/plain" \
   -d '{"d":"2021-11-12T08:48:06+0000","t":16207,"h":2061,"p":11022}'

エンティティの表示

リクエスト:

ngsi get \
  --host orion.local \
  --service openiot \
  --path / \
  entity \
  --id urn:ngsi-ld:WeatherObserved:sensor004 \
  --pretty

レスポンス:

{
  "id": "urn:ngsi-ld:WeatherObserved:sensor004",
  "type": "Sensor",
  "TimeInstant": {
    "type": "DateTime",
    "value": "2021-11-12T08:48:06.476Z",
    "metadata": {}
  },
  "atmosphericPressure": {
    "type": "Number",
    "value": 11022,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:48:06.476Z"
      }
    }
  },
  "dateObserved": {
    "type": "DateTime",
    "value": "2021-11-12T08:48:06.000Z",
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:48:06.476Z"
      }
    }
  },
  "location": {
    "type": "geo:json",
    "value": {
      "type": "Point",
      "coordinates": [
        139.7671,
        35.68117
      ]
    },
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:48:06.476Z"
      }
    }
  },
  "relativeHumidity": {
    "type": "Number",
    "value": 2061,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:48:06.476Z"
      }
    }
  },
  "temperature": {
    "type": "Number",
    "value": 16207,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2021-11-12T08:48:06.476Z"
      }
    }
  }
}

こちらの例を参照ください。

関連情報