IoT Agent for JSON
IoT Agent for JSON の健全性チェック
IoT Agent for JSON が起動したら、次のコマンドでステータスを確認できます:
リクエスト:
ngsi version --host iotagent-json.example.com --prettyレスポンス:
{
  "libVersion": "2.17.0",
  "port": "4041",
  "baseRoot": "/",
  "version": "1.19.0"
}IoT Agent for JSON over MQTT
サービスの作成
リクエスト:
ngsi services \
  --host iotagent-json.example.com \
  create \
  --apikey  SMoCnNjlrAfeFOtlaC8XAhM8o1 \
  --type Thing \
  --resource /iot/json \
   --cbroker http://orion:1026サービスの一覧表示
リクエスト:
ngsi services \
  --host iotagent-json.example.com \
  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.example.com \
  create \
  --data '{ \
  "devices": [
    {
      "device_id":   "sensor002",
      "apikey":      "SMoCnNjlrAfeFOtlaC8XAhM8o1",
      "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.example.com \
  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.example.com
  --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.example.com \
  --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.example.com \
  create \
  --apikey XaEMQ86tTBHCwN0C9MjiHXcYFX \
  --type Thing \
  --resource /iot/json \
  --cbroker http://orion:1026サービスの一覧表示
リクエスト:
ngsi services \
  --host iotagent-json.example.com \
  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.example.com \
  create \
  --data '{
  "devices": [
    {
      "device_id":   "sensor004",
      "apikey":      "XaEMQ86tTBHCwN0C9MjiHXcYFX",
      "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.example.com \
  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.example.com/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.example.com \
  --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"
      }
    }
  }
}例
こちらの例を参照ください。
関連情報
- iotagent-json - GitHub
- iotagnet-node-lib - GitHub
- iotagent-json - Read the docs
- iotagent-node-lib - Read the docs
- IoT Agent configuration API - Apiary
- iotagnet-node-lib - Read the docs
- IoT Agent for JSON - FIWARE Step-By-Step Tutorials for NGSIv2
- IoT Agent over MQTT - FIWARE Step-By-Step Tutorials for NGSIv2
- NGSI Go tutorial for IoT Agent
- orchestracities/quantumleap - Docker Hub