Skip to content

Commit f3dc34c

Browse files
committed
Update Scripts
1 parent f6616e0 commit f3dc34c

3 files changed

Lines changed: 45 additions & 38 deletions

File tree

README.md

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
<br/> [![Documentation](https://img.shields.io/readthedocs/fiware-tutorials.svg)](https://fiware-tutorials.rtfd.io)
1515

1616
This tutorial uses introduces the use of the MQTT protocol across IoT devices connecting to FIWARE. The
17-
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) IoT
18-
Agent created in the [previous tutorial](https://github.com/FIWARE/tutorials.IoT-Agent) is reconfigured to communicate
19-
with a set of dummy IoT devices using MQTT via a [Mosquitto](https://mosquitto.org/) message broker
17+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) IoT Agent
18+
created in the [previous tutorial](https://github.com/FIWARE/tutorials.IoT-Agent) is reconfigured to communicate with a
19+
set of dummy IoT devices using MQTT via a [Mosquitto](https://mosquitto.org/) message broker
2020

2121
The tutorial uses [cUrl](https://ec.haxx.se/) commands throughout, but is also available as
2222
[Postman documentation](https://fiware.github.io/tutorials.IoT-Agent/)
@@ -94,9 +94,9 @@ A summary of the differences between the two transport protocols can be seen bel
9494
| Higher Power Requirement | Low Power Requirement |
9595

9696
The JSON IoT Agent will only send or interpret messages using the
97-
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
98-
syntax, however it can be used to send and receive messages over multiple **transport** mechanisms. Therefore we are
99-
able to use the same FIWARE generic enabler to connect to a wider range of IoT devices.
97+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) syntax,
98+
however it can be used to send and receive messages over multiple **transport** mechanisms. Therefore we are able to use
99+
the same FIWARE generic enabler to connect to a wider range of IoT devices.
100100

101101
#### Mosquitto MQTT Broker
102102

@@ -117,12 +117,12 @@ seen on the JSON device monitor web page found at: `http://localhost:3000/device
117117
This application builds on the components created in
118118
[previous tutorials](https://github.com/FIWARE/tutorials.IoT-Agent/). It will make use of two FIWARE components - the
119119
[Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/) and the
120-
[IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/). Usage of the Orion Context Broker
121-
is sufficient for an application to qualify as _“Powered by FIWARE”_. Both the Orion Context Broker and the IoT Agent
122-
rely on open source [MongoDB](https://www.mongodb.com/) technology to keep persistence of the information they hold. We
123-
will also be using the dummy IoT devices created in the
124-
[previous tutorial](https://github.com/FIWARE/tutorials.IoT-Agent/) Additionally we will add an instance of the
125-
[Mosquitto](https://mosquitto.org/) MQTT broker which is open source and available under the EPL/EDL.
120+
[IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/). Usage of the Orion Context Broker is
121+
sufficient for an application to qualify as _“Powered by FIWARE”_. Both the Orion Context Broker and the IoT Agent rely
122+
on open source [MongoDB](https://www.mongodb.com/) technology to keep persistence of the information they hold. We will
123+
also be using the dummy IoT devices created in the [previous tutorial](https://github.com/FIWARE/tutorials.IoT-Agent/)
124+
Additionally we will add an instance of the [Mosquitto](https://mosquitto.org/) MQTT broker which is open source and
125+
available under the EPL/EDL.
126126

127127
Therefore the overall architecture will consist of the following elements:
128128

@@ -131,8 +131,8 @@ Therefore the overall architecture will consist of the following elements:
131131
- The FIWARE [IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/) which will:
132132
- receive southbound requests using [NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2) and convert
133133
them to
134-
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
135-
MQTT topics for the MQTT Broker
134+
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) MQTT
135+
topics for the MQTT Broker
136136
- listen to the **MQTT Broker** on registered topics to send measurements northbound
137137
- The [Mosquitto](https://mosquitto.org/) **MQTT Broker** which acts as a central communication point, passing MQTT
138138
topics between the **IoT Agent** and IoT devices as necessary.
@@ -141,8 +141,7 @@ Therefore the overall architecture will consist of the following elements:
141141
registrations
142142
- Used by the **IoT Agent** to hold device information such as device URLs and Keys
143143
- A webserver acting as set of [dummy IoT devices](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2) using
144-
the
145-
[JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
144+
the [JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual)
146145
protocol running over MQTT.
147146
- The **Context Provider NGSI** proxy is not used in this tutorial. It does the following:
148147
- receive requests using [NGSI-v2](https://fiware.github.io/specifications/OpenAPI/ngsiv2)
@@ -216,25 +215,25 @@ tutorial:
216215
The `tutorial` container is listening on two ports:
217216

218217
- Port `3000` is exposed so we can see the web page displaying the Dummy IoT devices.
219-
- Port `3001` is exposed purely for tutorial access - so that cUrl or Postman can make JSON commands without
220-
being part of the same network.
218+
- Port `3001` is exposed purely for tutorial access - so that cUrl or Postman can make JSON commands without being
219+
part of the same network.
221220

222221
The `tutorial` container is driven by environment variables as shown:
223222

224-
| Key | Value | Description |
225-
| ----------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
226-
| DEBUG | `tutorial:*` | Debug flag used for logging |
227-
| WEB_APP_PORT | `3000` | Port used by web-app which displays the dummy device data |
228-
| DUMMY_DEVICES_PORT | `3001` | Port used by the dummy IoT devices to receive commands |
223+
| Key | Value | Description |
224+
| ----------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
225+
| DEBUG | `tutorial:*` | Debug flag used for logging |
226+
| WEB_APP_PORT | `3000` | Port used by web-app which displays the dummy device data |
227+
| DUMMY_DEVICES_PORT | `3001` | Port used by the dummy IoT devices to receive commands |
229228
| DUMMY_DEVICES_API_KEY | `4jggokgpepnvsb2uv4s40d59ov` | Random security key used for JSON interactions - used to ensure the integrity of interactions between the devices and the IoT Agent |
230-
| DUMMY_DEVICES_TRANSPORT | `MQTT` | The transport protocol used by the dummy IoT devices |
229+
| DUMMY_DEVICES_TRANSPORT | `MQTT` | The transport protocol used by the dummy IoT devices |
231230

232231
The other `tutorial` container configuration values described in the YAML file are not used in this tutorial.
233232

234233
## IoT Agent for JSON Configuration
235234

236-
The [IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/) can be instantiated within a
237-
Docker container. An official Docker image is available from [Docker Hub](https://hub.docker.com/r/fiware/iotagent-json/)
235+
The [IoT Agent for JSON](https://fiware-iotagent-json.readthedocs.io/en/latest/) can be instantiated within a Docker
236+
container. An official Docker image is available from [Docker Hub](https://hub.docker.com/r/fiware/iotagent-json/)
238237
tagged `fiware/iotagent-json`. The necessary configuration can be seen below:
239238

240239
```yaml
@@ -284,7 +283,7 @@ The `iot-agent` container is driven by environment variables as shown:
284283
| IOTA_LOG_LEVEL | `DEBUG` | The log level of the IoT Agent |
285284
| IOTA_TIMESTAMP | `true` | Whether to supply timestamp information with each measurement received from attached devices |
286285
| IOTA_CB_NGSI_VERSION | `v2` | Whether to supply use NGSI v2 when sending updates for active attributes |
287-
| IOTA_AUTOCAST | `true` | Ensure JSON number values are read as numbers not strings |
286+
| IOTA_AUTOCAST | `true` | Ensure JSON number values are read as numbers not strings |
288287
| IOTA_MONGO_HOST | `context-db` | The hostname of mongoDB - used for holding device information |
289288
| IOTA_MONGO_PORT | `27017` | The port mongoDB is listening on |
290289
| IOTA_MONGO_DB | `iotagentul` | The name of the database used in mongoDB |
@@ -906,8 +905,8 @@ available. In other words the IoT Agent registered itself as a
906905
[Context Provider](https://github.com/FIWARE/tutorials.Context-Providers/) for the command attributes.
907906

908907
Once the commands have been registered it will be possible to ring the **Bell**, open and close the **Smart Door** and
909-
switch the **Smart Lamp** on and off by sending requests to the Orion Context Broker, rather than sending JSON
910-
requests directly the IoT devices as we did in the
908+
switch the **Smart Lamp** on and off by sending requests to the Orion Context Broker, rather than sending JSON requests
909+
directly the IoT devices as we did in the
911910
[previous tutorial](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2)
912911

913912
All the communications leaving and arriving at the North port of the IoT Agent use the standard NGSI syntax. The

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ services:
6161
- "${IOTA_NORTH_PORT}"
6262
ports:
6363
- "${IOTA_NORTH_PORT}:${IOTA_NORTH_PORT}" # localhost:4041
64+
deploy:
65+
resources:
66+
limits:
67+
memory: 1024M
68+
cpus: '2.0'
69+
reservations:
70+
memory: 512M
71+
cpus: '1.0'
6472
environment:
6573
- IOTA_CB_HOST=orion # name of the context broker to update context
6674
- IOTA_CB_PORT=${ORION_PORT} # port the context broker listens on to update context

services

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# This will force the script to use docker-compose which may be more reliable in
1515
# some cases (or if an older version of Docker is being used)
1616

17-
set -e
17+
set -eo pipefail
1818

1919
dockerCmd="docker compose"
2020
if (( $# == 2 )); then
@@ -71,7 +71,7 @@ addDatabaseIndex () {
7171

7272
waitForMongo () {
7373
echo -e "\n⏳ Waiting for \033[1mMongoDB\033[0m to be available\n"
74-
while ! [ `docker inspect --format='{{.State.Health.Status}}' db-mongo` == "healthy" ]
74+
while ! [ "$(docker inspect --format='{{.State.Health.Status}}' db-mongo)" == "healthy" ]
7575
do
7676
sleep 1
7777
done
@@ -80,20 +80,20 @@ waitForMongo () {
8080
waitForOrion () {
8181
echo -e "\n⏳ Waiting for \033[1;34mOrion\033[0m to be available\n"
8282

83-
while ! [ `docker inspect --format='{{.State.Health.Status}}' fiware-orion` == "healthy" ]
83+
while ! [ "$(docker inspect --format='{{.State.Health.Status}}' fiware-orion)" == "healthy" ]
8484
do
85-
echo -e "Context Broker HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:1026/version'` " (waiting for 200)"
85+
echo -e "Context Broker HTTP state: " $(curl -s -o /dev/null -w %{http_code} 'http://localhost:1026/version') " (waiting for 200)"
8686
sleep 1
8787
done
8888
}
8989

9090

9191
waitForIoTAgent () {
9292
echo -e "\n⏳ Waiting for \033[1;36mIoT-Agent\033[0m to be available\n"
93-
while ! [ `docker inspect --format='{{.State.Health.Status}}' fiware-iot-agent` == "healthy" ]
93+
while ! [ "$(docker inspect --format='{{.State.Health.Status}}' fiware-iot-agent)" == "healthy" ]
9494

9595
do
96-
echo -e "IoT Agent HTTP state: " `curl -s -o /dev/null -w %{http_code} 'http://localhost:4041/version'` " (waiting for 200)"
96+
echo -e "IoT Agent HTTP state: " $(curl -s -o /dev/null -w %{http_code} 'http://localhost:4041/version') " (waiting for 200)"
9797
sleep 1
9898
done
9999
}
@@ -104,7 +104,7 @@ case "${command}" in
104104
echo "usage: services [create|start|stop]"
105105
;;
106106
"start")
107-
export $(cat .env | grep "#" -v)
107+
set -a; source .env; set +a
108108
stoppingContainers
109109
echo -e "Starting containers: \033[1;34mOrion\033[0m, \033[1;36mIoT-Agent\033[0m, \033[1mTutorial\033[0m, \033[1mMosquitto\033[0m MQTT broker and a \033[1mMongoDB\033[0m database."
110110
echo -e "- \033[1;34mOrion\033[0m is the context broker"
@@ -121,11 +121,11 @@ case "${command}" in
121121
echo -e "Now open \033[4mhttp://localhost:3000/device/monitor\033[0m"
122122
;;
123123
"stop")
124-
export $(cat .env | grep "#" -v)
124+
set -a; source .env; set +a
125125
stoppingContainers
126126
;;
127127
"create")
128-
export $(cat .env | grep "#" -v)
128+
set -a; source .env; set +a
129129
echo "Pulling Docker images"
130130
docker pull -q quay.io/curl/curl
131131
${dockerCmd} pull --ignore-pull-failures

0 commit comments

Comments
 (0)