IoT Agent for UltraLight 2.0
IoT Agent for UL の健全性チェック
IoT Agent for UltraLight 2.0 が起動したら、次のコマンドでステータスを確認できます:
リクエスト:
ngsi version --host iotagent-ul.local --pretty
レスポンス:
{
"libVersion": "4.4.0",
"port": "4041",
"baseRoot": "/",
"version": "3.4.0"
}
IoT Agent for UL over MQTT
サービスの作成
リクエスト:
ngsi services \
--host iotagent-ul.local \
create \
--apikey 8f9z57ahxmtzx21oczr5vaabot \
--type Thing \
--resource /iot/ul \
--cbroker http://orion:1026
サービスの一覧表示
リクエスト:
ngsi services \
--host iotagent-ul.local \
list \
--pretty
レスポンス:
{
"count": 1,
"services": [
{
"commands": [],
"lazy": [],
"attributes": [],
"_id": "618cff6b36b21980226fffc2",
"resource": "/iot/ul",
"apikey": "8f9z57ahxmtzx21oczr5vaabot",
"service": "openiot",
"subservice": "/",
"__v": 0,
"static_attributes": [],
"internal_attributes": [],
"entity_type": "Thing"
}
]
}
デバイスの作成
リクエスト:
ngsi devices \
--host iotagent-ul.local \
create \
--data '{ \
"devices": [
{
"device_id": "sensor001",
"entity_name": "urn:ngsi-ld:WeatherObserved:sensor001",
"entity_type": "Sensor",
"timezone": "Asia/Tokyo",
"protocol": "PDI-IoTA-UltraLight",
"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-ul.local \
list \
--pretty
レスポンス:
{
"count": 1,
"devices": [
{
"device_id": "sensor001",
"service": "openiot",
"service_path": "/",
"entity_name": "urn:ngsi-ld:WeatherObserved:sensor001",
"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
]
}
}
],
"protocol": "PDI-IoTA-UltraLight",
"explicitAttrs": false
}
]
}
データの送信
リクエスト:
mosquitto_pub \
--debug \
--host mosquitto.local
--port 8883 \
--username fiware --pw ZSpi0wAz1e1ZImd8 \
--topic "/8f9z57ahxmtzx21oczr5vaabot/sensor001/attrs" \
--message "d|2021-11-11T11:36:49+0000|t|10465|h|27378|p|20617" \
--cafile ./config/mosquitto/isrgrootx1.pem
エンティティの表示
リクエスト:
ngsi get \
--host orion.local \
--service openiot \
--path / \
entity \
--id urn:ngsi-ld:WeatherObserved:sensor001 \
--pretty
レスポンス:
{
"id": "urn:ngsi-ld:WeatherObserved:sensor001",
"type": "Sensor",
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:36:49.576Z",
"metadata": {}
},
"atmosphericPressure": {
"type": "Number",
"value": 20617,
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:36:49.576Z"
}
}
},
"dateObserved": {
"type": "DateTime",
"value": "2021-11-11T11:36:49.000Z",
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:36:49.576Z"
}
}
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [
139.7671,
35.68117
]
},
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:36:49.576Z"
}
}
},
"relativeHumidity": {
"type": "Number",
"value": 27378,
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:36:49.576Z"
}
}
},
"temperature": {
"type": "Number",
"value": 10465,
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:36:49.576Z"
}
}
}
}
例
こちら の例を参照ください。
IoT Agent for UL over HTTP
サービスの作成
リクエスト:
ngsi services \
--host iotagent-ul.local \
create \
--apikey Dk8A0vfwTkTiAY71QyyKzOv9CT \
--type Thing \
--resource /iot/ul \
--cbroker http://orion:1026
サービスの一覧表示
リクエスト:
ngsi services \
--host iotagent-ul.local \
list \
--pretty
レスポンス:
{
"count": 1,
"services": [
{
"commands": [],
"lazy": [],
"attributes": [],
"_id": "618d03230e779727e4443d1a",
"resource": "/iot/ul",
"apikey": "Dk8A0vfwTkTiAY71QyyKzOv9CT",
"service": "openiot",
"subservice": "/",
"__v": 0,
"static_attributes": [],
"internal_attributes": [],
"entity_type": "Thing"
}
]
}
デバイスの作成
リクエスト:
ngsi devices \
--host iotagent-ul.local \
create \
--data '{
"devices": [
{
"device_id": "sensor003",
"entity_name": "urn:ngsi-ld:WeatherObserved:sensor003",
"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-ul.local \
list \
--pretty
レスポンス:
"count": 1,
"devices": [
{
"device_id": "sensor003",
"service": "openiot",
"service_path": "/",
"entity_name": "urn:ngsi-ld:WeatherObserved:sensor003",
"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=Dk8A0vfwTkTiAY71QyyKzOv9CT&i=sensor003" \
-u "fiware:AEAtp3JC6qxtPKah" \
-H "Content-Type: text/plain" \
-d "d|2021-11-11T11:59:14+0000|t|20641|h|8290|p|5371"
エンティティの表示
リクエスト:
ngsi get \
--host orion.local \
--service openiot \
--path / \
entity \
--id urn:ngsi-ld:WeatherObserved:sensor003 \
--pretty
レスポンス:
{
"id": "urn:ngsi-ld:WeatherObserved:sensor003",
"type": "Sensor",
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:59:14.440Z",
"metadata": {}
},
"atmosphericPressure": {
"type": "Number",
"value": 5371,
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:59:14.440Z"
}
}
},
"dateObserved": {
"type": "DateTime",
"value": "2021-11-11T11:59:14.000Z",
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:59:14.440Z"
}
}
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [
139.7671,
35.68117
]
},
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:59:14.440Z"
}
}
},
"relativeHumidity": {
"type": "Number",
"value": 8290,
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:59:14.440Z"
}
}
},
"temperature": {
"type": "Number",
"value": 20641,
"metadata": {
"TimeInstant": {
"type": "DateTime",
"value": "2021-11-11T11:59:14.440Z"
}
}
}
}
例
こちらの例を参照ください。
関連情報
- iotagent-ul - GitHub
- iotagnet-node-lib - GitHub
- iotagent-ul - Read the docs
- iotagent-node-lib - Read the docs
- IoT Agent configuration API - Apiary
- iotagnet-node-lib - Read the docs
- IoT Agent for UltraLight - FIWARE Step-By-Step Tutorials for NGSIv2
- IoT Agent over MQTT - FIWARE Step-By-Step Tutorials for NGSIv2
- NGSI Go tutorial for IoT Agent
- telefonicaiot/iotagent-ul - Docker Hub