Skip to content

Commit 10d5928

Browse files
committed
Switch to JSON IoT Agent
1 parent 60f008f commit 10d5928

10 files changed

Lines changed: 188 additions & 96 deletions

File tree

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ ORION_VERSION=4.1.0
99
MONGO_DB_PORT=27017
1010
MONGO_DB_VERSION=6.0
1111

12-
# IoT Agent Ultralight Variables
13-
ULTRALIGHT_VERSION=3.7.0-distroless
12+
# IoT Agent JSON Variables
13+
JSON_VERSION=3.14.0-distroless
1414
IOTA_NORTH_PORT=4041
1515
IOTA_SOUTH_PORT=7896
1616

.github/test/iot_device_smoke_test

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
#
3+
# Smoke test: verify IoT device provisioning by sending a 'ring' command to each
4+
# bell and confirming the context broker reflects the updated
5+
# ring_status attribute after the full command round-trip:
6+
# Orion → IoT Agent → iot-sensors simulator → IoT Agent → Orion
7+
#
8+
9+
set -e
10+
11+
# Load environment variables if available
12+
if [ -f .env ]; then
13+
export $(cat .env | grep "#" -v)
14+
fi
15+
16+
BROKER="http://orion:1026"
17+
TENANT="openiot"
18+
DEVICES=("Bell:001" "Bell:002")
19+
20+
failures=0
21+
22+
run_curl () {
23+
# If CURL_VERSION is not set, use latest
24+
local curl_img="quay.io/curl/curl:${CURL_VERSION:-latest}"
25+
docker run --rm --network fiware_default "${curl_img}" "$@"
26+
}
27+
28+
send_ring_command () {
29+
local device="$1"
30+
local status
31+
echo "Sending ring command to ${device}..."
32+
status=$(run_curl -s -o /dev/null -w "%{http_code}" \
33+
-X POST \
34+
"${BROKER}/v2/op/update" \
35+
-H "fiware-service: ${TENANT}" \
36+
-H "fiware-servicepath: /" \
37+
-H 'Content-Type: application/json' \
38+
--data-raw '{
39+
"actionType": "update",
40+
"entities": [
41+
{
42+
"id": "'"${device}"'",
43+
"type": "Bell",
44+
"ring": {
45+
"type": "command",
46+
"value": ""
47+
}
48+
}
49+
]
50+
}')
51+
if [ "${status}" != "204" ]; then
52+
echo "FAIL [${device}]: ring command returned HTTP ${status} (expected 204)"
53+
return 1
54+
fi
55+
echo "PASS [${device}]: ring command accepted (204)"
56+
}
57+
58+
check_ring_status () {
59+
local device="$1"
60+
local response
61+
echo "Checking ring_status for ${device}..."
62+
response=$(run_curl -s \
63+
"${BROKER}/v2/entities/${device}?attrs=ring_status" \
64+
-H "fiware-service: ${TENANT}" \
65+
-H "fiware-servicepath: /" \
66+
-H 'Accept: application/json')
67+
if ! echo "${response}" | grep -q '"ring_status"'; then
68+
echo "FAIL [${device}]: ring_status attribute missing from context broker"
69+
echo " Response: ${response}"
70+
return 1
71+
fi
72+
if ! echo "${response}" | grep -q '"value":"OK"'; then
73+
echo "FAIL [${device}]: ring_status is not OK"
74+
echo " Response: ${response}"
75+
return 1
76+
fi
77+
echo "PASS [${device}]: ring_status confirmed as OK in context broker"
78+
}
79+
80+
for device in "${DEVICES[@]}"; do
81+
send_ring_command "${device}" || failures=$((failures + 1))
82+
done
83+
84+
echo "Waiting 5s for command round-trip..."
85+
sleep 5
86+
87+
for device in "${DEVICES[@]}"; do
88+
check_ring_status "${device}" || failures=$((failures + 1))
89+
done
90+
91+
echo ""
92+
if [ "${failures}" -gt 0 ]; then
93+
echo "Smoke test FAILED: ${failures} assertion(s) did not pass"
94+
exit 1
95+
fi
96+
echo "Smoke test PASSED: all bell devices are responding and context broker is updated"

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ jobs:
2929
./services create || true
3030
- name: Run Script
3131
run: |
32-
./services start && ./services stop
32+
./services start
33+
./.github/test/iot_device_smoke_test
34+
./services stop

README.ja.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Proxy** インスタンスを追加することで、既存の在庫管理、お
207207
プリケーションへのアクセスを保護し、**Keyrock** が使用する **MySQL** データベー
208208
スに事前入力されたデータを使用します
209209
[Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/),
210-
[IoT Agent for UltraLight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/),
210+
[IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/),
211211
[Keyrock](https://fiware-idm.readthedocs.io/en/latest/) Generic Enabler の 4 つ
212212
の FIWARE コンポーネントを使用し、[Wilma](https://fiware-pep-proxy.rtfd.io/)
213213
**PEP Proxy** の 1 つまたは 2 つのインスタンスを追加して、どのインタフェースを保
@@ -227,10 +227,10 @@ Orion Context Broker と IoT Agent はオープンソースの
227227
[Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/)
228228
[NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2) を使用して
229229
リクエストを受信します
230-
- [IoT Agent for UltraLight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/)
230+
- [IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/)
231231
は、[NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2) を使用し
232232
てサウスバウンド・リクエストを受信し、それをデバイスのために
233-
[UltraLight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
233+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
234234
に変換します。
235235
- FIWARE [Keyrock](https://fiware-idm.readthedocs.io/en/latest/) は、以下を含
236236
んだ、補完的な ID 管理システムを提供します :
@@ -254,7 +254,7 @@ Orion Context Broker と IoT Agent はオープンソースの
254254
- ユーザが製品を"購入"して在庫数を減らすことができます
255255
- 許可されたユーザを制限されたエリアに入れることができます
256256
- HTTP を介して実行されている
257-
[UltraLight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
257+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
258258
プロトコルを使用す
259259
[ダミー IoT デバイス](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2)のセ
260260
ットとして機能する Web サーバ。特定のリソースへのアクセスが制限されています
@@ -1151,7 +1151,7 @@ async function buyItem(req, res) {
11511151

11521152
`iot-agent-proxy` コンテナは FIWARE **Wilma** のインスタンスである、ポート
11531153
`7897` で待機し、`iot-agent` のポート `7896` にトラフィックを転送するように設定
1154-
され これは、Ultralight エージェントが、HTTP リクエストのために待機しているデフ
1154+
され これは、JSON エージェントが、HTTP リクエストのために待機しているデフ
11551155
ォルトのポートです。
11561156

11571157
```yaml
@@ -1218,7 +1218,7 @@ iot-agent-proxy:
12181218
## IoT Agent サウス・ポート の保護 - アプリケーションの設定
12191219

12201220
このチュートリアル・アプリケーションは、ダミー IoT センサのデータを提供する役割
1221-
も果たします。IoT センサは、Ultralight 構文でコマンドと測定値を含む HTTP リクエ
1221+
も果たします。IoT センサは、JSON 構文でコマンドと測定値を含む HTTP リクエ
12221222
ストを出しています。IoT センサのユーザ名とパスワードはすでに **Keyrock** に登録
12231223
されていますが、プログラムごとに OAuth2 アクセス・トークンを取得し、**IoT
12241224
Agent** の前にある 2 番目の **Wilma** PEP Proxy にリクエストします。
@@ -1254,7 +1254,7 @@ tutorial-app:
12541254
- "DUMMY_DEVICES_PASSWORD=test"
12551255
```
12561256

1257-
`tutorial` コンテナは、ダミー Ultralight センサをホストします。以前のすべてのチ
1257+
`tutorial` コンテナは、ダミー JSON センサをホストします。以前のすべてのチ
12581258
ュートリアルに示されているように、**IoT Agent** にポート `7896` で直接アクセスす
12591259
るのではなく、すべてのトラフィックが、`iot-agent-proxy` の ポート `7897` に転送
12601260
されます。関連する `tutorial` コンテナの設定のほとんどは、以前のチュートリアルで
@@ -1267,7 +1267,7 @@ tutorial-app:
12671267
| IOTA_HTTP_PORT | `7896` | IoT Agent を保護する Wilma PEP Proxy がリスンしているポート |
12681268
| DUMMY_DEVICES_PORT | `3001` | ダミー IoT デバイスがコマンドを受信するために使用するポート |
12691269
| DUMMY_DEVICES_TRANSPORT | `HTTP` | ダミー IoT デバイスによって使用されるデフォルトのトランスポート |
1270-
| DUMMY_DEVICES_API_KEY | `4jggokgpepnvsb2uv4s40d59ov` | UltraLight インタラクションに使用されるランダムなセキュリティキー - デバイスと IoT Agent 間のインタラクションの完全性を保証します |
1270+
| DUMMY_DEVICES_API_KEY | `4jggokgpepnvsb2uv4s40d59ov` | JSON インタラクションに使用されるランダムなセキュリティキー - デバイスと IoT Agent 間のインタラクションの完全性を保証します |
12711271
| DUMMY_DEVICES_USER | `iot_sensor_00000000-0000-0000-0000-000000000000` | **Keyrock** のデバイスに割り当てられたユーザ名 |
12721272
| DUMMY_DEVICES_PASSWORD | `test` | **Keyrock** のデバイスに割り当てられたパスワード |
12731273

@@ -1332,7 +1332,7 @@ curl -iX POST \
13321332
この例では、デバイス `motion001` からの保護されたリクエストをシミュレートします
13331333
13341334

1335-
Ultralight IoT Agent の前にある PEP Proxy への POST リクエストは、事前にプロビジ
1335+
JSON IoT Agent の前にある PEP Proxy への POST リクエストは、事前にプロビジ
13361336
ョニングされたリソース `iot/d` エンドポイントを識別し、デバイス `motion001` の測
13371337
定値を渡します。`X-Auth-Token` ヘッダを追加すると、リクエスト元が Keyrock に登録
13381338
されていると識別され、測定が IoT Agent 自体に正常に渡されます。
@@ -1341,7 +1341,7 @@ Ultralight IoT Agent の前にある PEP Proxy への POST リクエストは、
13411341

13421342
```console
13431343
curl -X POST \
1344-
'http://localhost:7897/iot/d?k=1068318794&i=motion001' \
1344+
'http://localhost:7897/iot/json?k=1068318794&i=motion001' \
13451345
-H 'X-Auth-Token: {{X-Access-token}}' \
13461346
-H 'Content-Type: text/plain' \
13471347
-d 'c|1'
@@ -1409,7 +1409,7 @@ request(options, (error) => {
14091409
iot-agent:
14101410
labels:
14111411
org.fiware: 'tutorial'
1412-
image: quay.io/fiware/iotagent-ul:${ULTRALIGHT_VERSION}
1412+
image: quay.io/fiware/iotagent-json:${JSON_VERSION}
14131413
hostname: iot-agent
14141414
container_name: fiware-iot-agent
14151415
depends_on:
@@ -1431,7 +1431,7 @@ iot-agent:
14311431
- IOTA_AUTOCAST=true
14321432
- IOTA_MONGO_HOST=mongo-db
14331433
- IOTA_MONGO_PORT=27017
1434-
- IOTA_MONGO_DB=iotagentul
1434+
- IOTA_MONGO_DB=iotagentjson
14351435
- IOTA_HTTP_PORT=7896
14361436
- IOTA_PROVIDER_URL=http://iot-agent:4041
14371437
- IOTA_AUTH_ENABLED=true
@@ -1514,15 +1514,15 @@ curl -X POST \
15141514
"apikey": "1068318794",
15151515
"cbroker": "http://orion:1026",
15161516
"entity_type": "Motion",
1517-
"resource": "/iot/d"
1517+
"resource": "/iot/json"
15181518
}
15191519
```
15201520

15211521
#### 1️⃣8️⃣ リクエスト:
15221522

15231523
```console
15241524
curl -iX PUT \
1525-
'http://localhost:4041/iot/services?resource=/iot/d&apikey=1068318794' \
1525+
'http://localhost:4041/iot/services?resource=/iot/json&apikey=1068318794' \
15261526
-H 'Content-Type: application/json' \
15271527
-H 'fiware-service: openiot' \
15281528
-H 'fiware-servicepath: /' \
@@ -1544,7 +1544,7 @@ curl -iX PUT \
15441544

15451545
```console
15461546
curl -iX POST \
1547-
'http://localhost:4041/iot/devices' \
1547+
'http://localhost:4041/iot/jsonevices' \
15481548
-H 'Content-Type: application/json' \
15491549
-H 'fiware-service: openiot' \
15501550
-H 'fiware-servicepath: /' \

0 commit comments

Comments
 (0)