Skip to content

Commit ab64925

Browse files
committed
Switch to JSON IoT Agent
1 parent bec9551 commit ab64925

7 files changed

Lines changed: 139 additions & 42 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ FIWARE [QuantumLeap](https://quantumleap.readthedocs.io/en/latest/) は、永続
140140
このチュートリアルの目的のために、一連のダミー IoT デバイスが作成され、Context Broker に接続されます。使用しているアーキ
141141
テクチャとプロトコルの詳細は
142142
[IoT Sensors チュートリアル](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2)にあります。各デバイスの状態
143-
は、次の UltraLight デバイス・モニタの Web ページで確認できます : `http://localhost:3000/device/monitor`
143+
は、次の JSON デバイス・モニタの Web ページで確認できます : `http://localhost:3000/device/monitor`
144144

145145
![FIWARE Monitor](https://fiware.github.io/tutorials.Time-Series-Data/img/device-monitor.png)
146146

@@ -159,7 +159,7 @@ FIWARE [QuantumLeap](https://quantumleap.readthedocs.io/en/latest/) は、永続
159159

160160
このアプリケーションは、[以前のチュートリアル](https://github.com/FIWARE/tutorials.IoT-Agent/) で作成したコンポーネント
161161
とダミー IoT デバイスをベースにしています
162-
[Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/)[IoT Agent for Ultralight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/)
162+
[Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/)[IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/)
163163
および [QuantumLeap](https://quantumleap.readthedocs.io/en/latest/) の 3 つの FIWARE コンポーネントを使用します。
164164

165165
したがって、全体的なアーキテクチャは次の要素で構成されます :
@@ -168,7 +168,7 @@ FIWARE [QuantumLeap](https://quantumleap.readthedocs.io/en/latest/) は、永続
168168

169169
- FIWARE [Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/)
170170
[NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2) を使用してリクエストを受信します
171-
- FIWARE [IoT Agent for Ultralight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/) は、Ultralight 2.0
171+
- FIWARE [IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/) は、JSON
172172
形式のダミー IoT デバイスからノース・バウンドの測定値を受信し、Context Broker の
173173
[NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2) リクエストに変換してコンテキスト・エンティティ
174174
の状態を変更します
@@ -187,7 +187,7 @@ FIWARE [QuantumLeap](https://quantumleap.readthedocs.io/en/latest/) は、永続
187187
- 時間ベースのデータクエリを解釈する HTTP エンドポイントを提供します
188188

189189
- **コンテキストプロバイダ** : - HTTP 上で動作する
190-
[Ultralight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
190+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
191191
プロトコルを使用して、 [ダミー IoT デバイス](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2)のセットと
192192
して機能する Web サーバです。 - このチュートリアルでは、 **コンテキスト・プロバイダの NGSI proxy** は使用しません
193193

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ available licensed under the Apache License 2.0. More information can be found a
137137
For the purpose of this tutorial, a series of dummy IoT devices have been created, which will be attached to the context
138138
broker. Details of the architecture and protocol used can be found in the
139139
[IoT Sensors tutorial](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2). The state of each device can be
140-
seen on the UltraLight device monitor web page found at: `http://localhost:3000/device/monitor`
140+
seen on the JSON device monitor web page found at: `http://localhost:3000/device/monitor`
141141

142142
![FIWARE Monitor](https://fiware.github.io/tutorials.Time-Series-Data/img/device-monitor.png)
143143

@@ -153,7 +153,7 @@ web page found at: `http://localhost:3000/device/history/urn:ngsi-ld:Store:001`
153153
This application builds on the components and dummy IoT devices created in
154154
[previous tutorials](https://github.com/FIWARE/tutorials.IoT-Agent/). It will use three FIWARE components: the
155155
[Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/), the
156-
[IoT Agent for Ultralight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/), and
156+
[IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/), and
157157
[QuantumLeap](https://smartsdk.github.io/ngsi-timeseries-api/) .
158158

159159
Therefore the overall architecture will consist of the following elements:
@@ -162,9 +162,9 @@ Therefore the overall architecture will consist of the following elements:
162162

163163
- The FIWARE [Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/) which will receive requests
164164
using [NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2)
165-
- The FIWARE [IoT Agent for Ultralight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/) which will
166-
receive northbound measurements from the dummy IoT devices in
167-
[Ultralight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
165+
- The FIWARE [IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/) which will receive
166+
northbound measurements from the dummy IoT devices in
167+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
168168
format and convert them to [NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2) requests for the
169169
context broker to alter the state of the context entities
170170
- FIWARE [QuantumLeap](https://quantumleap.readthedocs.io/en/latest/) subscribed to context changes and persisting
@@ -183,9 +183,9 @@ Therefore the overall architecture will consist of the following elements:
183183

184184
- A **Context Provider**: - A webserver acting as set of
185185
[dummy IoT devices](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2) using the
186-
[Ultralight 2.0](https://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
187-
protocol running over HTTP. - Note the **Stock Management Frontend** and **Context Provider NGSI** proxy are not
188-
used in this tutorial.
186+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) protocol
187+
running over HTTP. - Note the **Stock Management Frontend** and **Context Provider NGSI** proxy are not used in this
188+
tutorial.
189189

190190
Since all interactions between the elements are initiated by HTTP requests, the entities can be containerized and run
191191
from exposed ports.

docker-compose.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ services:
5858
healthcheck:
5959
test: curl --fail -s http://quantumleap:${QUANTUMLEAP_PORT}/version || exit 1
6060

61-
# IoT-Agent is configured for the UltraLight Protocol
61+
# IoT-Agent is configured for the JSON Protocol
6262
iot-agent:
6363
labels:
6464
org.fiware: 'tutorial'
65-
image: quay.io/fiware/iotagent-ul:${ULTRALIGHT_VERSION}
65+
image: quay.io/fiware/iotagent-json:${JSON_VERSION}
6666
hostname: iot-agent
6767
container_name: fiware-iot-agent
6868
depends_on:
@@ -82,9 +82,7 @@ services:
8282
- IOTA_TIMESTAMP=true # Supply timestamp information with each measurement
8383
- IOTA_CB_NGSI_VERSION=v2 # use NGSIv2 when sending updates for active attributes
8484
- IOTA_AUTOCAST=true # Ensure Ultralight number values are read as numbers not strings
85-
- IOTA_MONGO_HOST=mongo-db # The host name of MongoDB
86-
- IOTA_MONGO_PORT=${MONGO_DB_PORT} # The port mongoDB is listening on
87-
- IOTA_MONGO_DB=iotagentul # The name of the database used in mongoDB
85+
- IOTA_MONGO_URI=mongodb://mongo-db:${MONGO_DB_PORT}/iotagentjson # The name of the database used in mongoDB
8886
- IOTA_HTTP_PORT=${IOTA_SOUTH_PORT} # The port used for device traffic over HTTP
8987
- IOTA_PROVIDER_URL=http://iot-agent:${IOTA_NORTH_PORT}
9088
- IOTA_MULTI_CORE=true
@@ -121,9 +119,10 @@ services:
121119
- "WEB_APP_PORT=${TUTORIAL_APP_PORT}" # Port used by the content provider proxy and web-app for viewing data
122120
- "IOTA_HTTP_HOST=iot-agent"
123121
- "IOTA_HTTP_PORT=${IOTA_SOUTH_PORT}"
124-
- "IOTA_DEFAULT_RESOURCE=/iot/d"
122+
- "IOTA_DEFAULT_RESOURCE=/iot/json"
125123
- "DUMMY_DEVICES_PORT=${TUTORIAL_DUMMY_DEVICE_PORT}" # Port used by the dummy IOT devices to receive commands
126124
- "DUMMY_DEVICES_TRANSPORT=HTTP" # Default transport used by dummy Io devices
125+
- "DUMMY_DEVICES_PAYLOAD=JSON"
127126
- "CONTEXT_BROKER=http://orion:${ORION_PORT}/v2" # URL of the context broker to update context
128127
- "NGSI_LD_PREFIX="
129128
- "CRATE_DB_SERVICE_URL=http://crate-db:4200/_sql"

provision-devices

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ printf "⏳ Provisioning IoT devices "
1010

1111

1212
#
13-
# Create a service groups for all UltraLight IoT devices
13+
# Create a service groups for all JSON IoT devices
1414
#
1515

1616
curl -s -o /dev/null -X POST \
@@ -24,8 +24,8 @@ curl -s -o /dev/null -X POST \
2424
"apikey": "1068318794",
2525
"cbroker": "'"http://orion:$ORION_PORT"'",
2626
"entity_type": "Motion",
27-
"resource": "/iot/d",
28-
"protocol": "PDI-IoTA-UltraLight",
27+
"resource": "/iot/json",
28+
"protocol": "IoTA-JSON",
2929
"transport": "HTTP",
3030
"timezone": "Europe/Berlin",
3131
"attributes": [
@@ -35,16 +35,16 @@ curl -s -o /dev/null -X POST \
3535
{"name": "category", "type":"Text", "value": ["sensor"]},
3636
{"name": "controlledProperty", "type": "Text", "value": "motion"},
3737
{"name": "function", "type": "Text", "value":["sensing"]},
38-
{"name": "supportedProtocol", "type": "Text", "value": ["ul20"]},
38+
{"name": "supportedProtocol", "type": "Text", "value": ["json"]},
3939
{"name": "supportedUnits", "type": "Text", "value": "C62"}
4040
]
4141
},
4242
{
4343
"apikey": "3020035",
4444
"cbroker": "'"http://orion:$ORION_PORT"'",
4545
"entity_type": "Bell",
46-
"resource": "/iot/d",
47-
"protocol": "PDI-IoTA-UltraLight",
46+
"resource": "/iot/json",
47+
"protocol": "IoTA-JSON",
4848
"transport": "HTTP",
4949
"timezone": "Europe/Berlin",
5050
"commands": [
@@ -57,15 +57,15 @@ curl -s -o /dev/null -X POST \
5757
{"name": "category", "type":"Text", "value": ["actuator"]},
5858
{"name": "controlledProperty", "type": "Text", "value": "noiseLevel"},
5959
{"name": "function", "type": "Text", "value":["onOff"]},
60-
{"name": "supportedProtocol", "type": "Text", "value": ["ul20"]}
60+
{"name": "supportedProtocol", "type": "Text", "value": ["json"]}
6161
]
6262
},
6363
{
6464
"apikey": "3314136",
6565
"cbroker": "'"http://orion:$ORION_PORT"'",
6666
"entity_type": "Lamp",
67-
"resource": "/iot/d",
68-
"protocol": "PDI-IoTA-UltraLight",
67+
"resource": "/iot/json",
68+
"protocol": "IoTA-JSON",
6969
"transport": "HTTP",
7070
"timezone": "Europe/Berlin",
7171
"commands": [
@@ -82,16 +82,16 @@ curl -s -o /dev/null -X POST \
8282
{"name": "category", "type":"Text", "value": ["actuator","sensor"]},
8383
{"name": "controlledProperty", "type": "Text", "value": "light"},
8484
{"name": "function", "type": "Text", "value":["onOff", "sensing"]},
85-
{"name": "supportedProtocol", "type": "Text", "value": ["ul20"]},
85+
{"name": "supportedProtocol", "type": "Text", "value": ["json"]},
8686
{"name": "supportedUnits", "type": "Text", "value": "CDL"}
8787
]
8888
},
8989
{
9090
"apikey": "3089326",
9191
"cbroker": "'"http://orion:$ORION_PORT"'",
9292
"entity_type": "Door",
93-
"resource": "/iot/d",
94-
"protocol": "PDI-IoTA-UltraLight",
93+
"resource": "/iot/json",
94+
"protocol": "IoTA-JSON",
9595
"transport": "HTTP",
9696
"timezone": "Europe/Berlin",
9797
"commands": [
@@ -107,7 +107,7 @@ curl -s -o /dev/null -X POST \
107107
{"name": "category", "type":"Text", "value": ["actuator", "sensor"]},
108108
{"name": "controlledProperty", "type": "Text", "value": "state"},
109109
{"name": "function", "type": "Text", "value":["openClose", "eventNotification"]},
110-
{"name": "supportedProtocol", "type": "Text", "value": ["ul20"]}
110+
{"name": "supportedProtocol", "type": "Text", "value": ["json"]}
111111
]
112112
}
113113
]
@@ -119,7 +119,7 @@ curl -s -o /dev/null -X POST \
119119
#
120120

121121
curl -s -o /dev/null -X POST \
122-
"http://iot-agent:$IOTA_NORTH_PORT/iot/devices" \
122+
"http://iot-agent:$IOTA_NORTH_PORT/iot/jsonevices" \
123123
-H 'Content-Type: application/json' \
124124
-H 'fiware-service: openiot' \
125125
-H 'fiware-servicepath: /' \
@@ -149,7 +149,7 @@ curl -s -o /dev/null -X POST \
149149
"entity_name": "Door:001",
150150
"entity_type": "Door",
151151
"apikey": "3089326",
152-
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/door001"'",
152+
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/jsonoor001"'",
153153
"static_attributes": [
154154
{"name": "refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
155155
]
@@ -180,7 +180,7 @@ curl -s -o /dev/null -X POST \
180180
#
181181

182182
curl -s -o /dev/null -X POST \
183-
"http://iot-agent:$IOTA_NORTH_PORT/iot/devices" \
183+
"http://iot-agent:$IOTA_NORTH_PORT/iot/jsonevices" \
184184
-H 'Content-Type: application/json' \
185185
-H 'fiware-service: openiot' \
186186
-H 'fiware-servicepath: /' \
@@ -210,7 +210,7 @@ curl -s -o /dev/null -X POST \
210210
"entity_name": "Door:002",
211211
"entity_type": "Door",
212212
"apikey": "3089326",
213-
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/door002"'",
213+
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/jsonoor002"'",
214214
"static_attributes": [
215215
{"name": "refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:002"}
216216
]
@@ -244,7 +244,7 @@ curl -s -o /dev/null -X POST \
244244
#
245245

246246
curl -s -o /dev/null -X POST \
247-
"http://iot-agent:$IOTA_NORTH_PORT/iot/devices" \
247+
"http://iot-agent:$IOTA_NORTH_PORT/iot/jsonevices" \
248248
-H 'Content-Type: application/json' \
249249
-H 'fiware-service: openiot' \
250250
-H 'fiware-servicepath: /' \
@@ -274,7 +274,7 @@ curl -s -o /dev/null -X POST \
274274
"entity_name": "Door:003",
275275
"entity_type": "Door",
276276
"apikey": "3089326",
277-
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/door003"'",
277+
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/jsonoor003"'",
278278
"static_attributes": [
279279
{"name": "refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:003"}
280280
]
@@ -307,7 +307,7 @@ curl -s -o /dev/null -X POST \
307307
#
308308

309309
curl -s -o /dev/null -X POST \
310-
"http://iot-agent:$IOTA_NORTH_PORT/iot/devices" \
310+
"http://iot-agent:$IOTA_NORTH_PORT/iot/jsonevices" \
311311
-H 'Content-Type: application/json' \
312312
-H 'fiware-service: openiot' \
313313
-H 'fiware-servicepath: /' \
@@ -337,7 +337,7 @@ curl -s -o /dev/null -X POST \
337337
"entity_name": "Door:004",
338338
"entity_type": "Door",
339339
"apikey": "3089326",
340-
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/door004"'",
340+
"endpoint": "'"http://iot-sensors:$TUTORIAL_DUMMY_DEVICE_PORT/iot/jsonoor004"'",
341341
"static_attributes": [
342342
{"name": "refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:004"}
343343
]

0 commit comments

Comments
 (0)