Commit 7204546e authored by Federico Sismondi's avatar Federico Sismondi

First version of PoC/demo for IoT platform powered by FIWARE

parents
MIT License
Copyright (c) 2018-2020 FIWARE Foundation e.V.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Goals
This is a PoC showing how to use FIWARE components for building an IoT platoform / Secured communication platform
This is inspired from [FIWARE tutorial](https://github.com/Fiware/tutorials.PEP-Proxy/blob/master/README.md)
# OVERALL ARCHITECTURE
+----------------------+ +-------------------+
| | | |
| Cloud Core Platform +----------------+ WMS - Watering |
| | | weekly scheduler |
+----------+-----------+ | |
| +-------------------+
|
|
|
+----------+-----------+
| |
| Soil Moisture IoT |
| sensor |
| |
+----------------------+
+------------------------------------------------------------------------------+
# WMS subscribes:
+----------------------+ +-------------------+
| | | |
| Cloud Core Platform +<---------------+ WMS - Watering |
| | SUBSCRIBE | weekly scheduler |
+----------------------+ /FlowerBed/soilMoistureVwc |
+-------------------+
+----------------------+
| |
| Soil Moisture IoT |
| sensor |
| |
+----------------------+
+------------------------------------------------------------------------------+
# IoT data update, forwarding data to subscribers
+----------------------+ +-------------------+
| | | |
| Cloud Core Platform +--------------->+ WMS - Watering |
| | POST | weekly scheduler |
+-----+----------------+ /FlowerBed/soilMoistureVwc |
^ +-------------------+
UPDATE|
/FlowerBed/soilMoistureVwc
|
+-----+----------------+
| |
| Soil Moisture IoT |
| sensor |
| |
+----------------------+
+------------------------------------------------------------------------------+
# Requirements
- install `docker-compose`
- get source code repo
# Demo steps
## Put platform up
`docker-compose up -d`
## Test pulling data from platform without token
```bash
curl -X GET http://localhost:1027/v2/entities/urn:ngsi-ld:Store:001\?options\=keyValues
Auth-token not found in request header
```
##
# WARNING: Do not deploy this tutorial configuration directly to a production environment
#
# The tutorial docker-compose files have not been written for production deployment and will not
# scale. A proper architecture has been sacrificed to keep the narrative focused on the learning
# goals, they are just used to deploy everything onto a single Docker machine. All FIWARE components
# are running at full debug and extra ports have been exposed to allow for direct calls to services.
# They also contain various obvious security flaws - passwords in plain text, no load balancing,
# no use of HTTPS and so on.
#
# This is all to avoid the need of multiple machines, generating certificates, encrypting secrets
# and so on, purely so that a single docker-compose file can be read as an example to build on,
# not use directly.
#
# When deploying to a production environment, please looking at the SmartSDK Recipes
# in order to scale up to a proper architecture:
#
# see: https://smartsdk.github.io/smartsdk-recipes/
#
version: "3.5"
services:
# Orion is the context broker
orion:
image: fiware/orion:${ORION_VERSION}
hostname: orion
container_name: fiware-orion
depends_on:
- mongo-db
networks:
default:
ipv4_address: 172.18.1.9
expose:
- "${ORION_PORT}"
ports:
- "${ORION_PORT}:${ORION_PORT}" # localhost:1026
command: -dbhost mongo-db -logLevel DEBUG
healthcheck:
test: curl --fail -s http://orion:${ORION_PORT}/version || exit 1
# Keyrock is an Identity Management Front-End
keyrock:
image: fiware/idm:${KEYROCK_VERSION}
container_name: fiware-keyrock
hostname: keyrock
networks:
default:
ipv4_address: 172.18.1.5
depends_on:
- mysql-db
ports:
- "${KEYROCK_PORT}:${KEYROCK_PORT}" # localhost:3005
environment:
- DEBUG=idm:*
- IDM_DB_HOST=mysql-db
- IDM_DB_PASS_FILE=/run/secrets/my_secret_data
- IDM_DB_USER=root
- IDM_HOST=http://localhost:${KEYROCK_PORT}
- IDM_PORT=${KEYROCK_PORT}
- IDM_HTTPS_ENABLED=${IDM_HTTPS_ENABLED}
- IDM_HTTPS_PORT=${KEYROCK_HTTPS_PORT}
- IDM_ADMIN_USER=alice
- IDM_ADMIN_EMAIL=alice-the-admin@test.com
- IDM_ADMIN_PASS=test
secrets:
- my_secret_data
healthcheck:
test: curl --fail -s http://localhost:${KEYROCK_PORT}/version || exit 1
# PEP Proxy for Orion
orion-proxy:
image: fiware/pep-proxy:${WILMA_VERSION}
container_name: fiware-orion-proxy
hostname: orion-proxy
networks:
default:
ipv4_address: 172.18.1.10
depends_on:
- keyrock
ports:
- "${ORION_PROXY_PORT}:${ORION_PROXY_PORT}" # localhost:1027
expose:
- "${ORION_PROXY_PORT}"
environment:
- PEP_PROXY_APP_HOST=orion
- PEP_PROXY_APP_PORT=${ORION_PORT}
- PEP_PROXY_PORT=${ORION_PROXY_PORT}
- PEP_PROXY_IDM_HOST=keyrock
- PEP_PROXY_HTTPS_ENABLED=false
- PEP_PROXY_AUTH_ENABLED=false
- PEP_PROXY_IDM_SSL_ENABLED=false
- PEP_PROXY_IDM_PORT=${KEYROCK_PORT}
- PEP_PROXY_APP_ID=tutorial-dckr-site-0000-xpresswebapp
- PEP_PROXY_USERNAME=pep_proxy_00000000-0000-0000-0000-000000000000
- PEP_PASSWORD=test
- PEP_PROXY_PDP=idm
- PEP_PROXY_MAGIC_KEY=1234
- PEP_PROXY_PUBLIC_PATHS=/version
healthcheck:
test: curl --fail -s http://orion-proxy:${ORION_PROXY_PORT}/version || exit 1
# Databases
mongo-db:
image: mongo:${MONGO_DB_VERSION}
hostname: mongo-db
container_name: db-mongo
expose:
- "${MONGO_DB_PORT}"
ports:
- "${MONGO_DB_PORT}:${MONGO_DB_PORT}" # localhost:27017
networks:
- default
command: --bind_ip_all --smallfiles
volumes:
- mongo-db:/data
# mongo admin dashboard
mongo-express:
image: mongo-express
container_name: mongo-express
networks:
- default
depends_on:
- mongo-db
expose:
- "8081"
ports:
- "8081:${MYSQL_DB_PORT}"
environment:
- ME_CONFIG_OPTIONS_EDITORTHEME=ambiance
- ME_CONFIG_BASICAUTH_USERNAME=user
- ME_CONFIG_BASICAUTH_PASSWORD=pass
- ME_CONFIG_MONGODB_PORT=${MONGO_DB_PORT}
- ME_CONFIG_MONGODB_ENABLE_ADMIN=false
- ME_CONFIG_MONGODB_SERVER=mongo-db
mysql-db:
restart: always
image: mysql:${MYSQL_DB_VERSION}
hostname: mysql-db
container_name: db-mysql
expose:
- "${MYSQL_DB_PORT}"
ports:
- "${MYSQL_DB_PORT}:${MYSQL_DB_PORT}" # localhost:3306
networks:
default:
ipv4_address: 172.18.1.6
environment:
- "MYSQL_ROOT_PASSWORD_FILE=/run/secrets/my_secret_data"
- "MYSQL_ROOT_HOST=172.18.1.5" # Allow Keyrock to access this database
volumes:
- mysql-db:/var/lib/mysql
- ./mysql-data:/docker-entrypoint-initdb.d/:ro
secrets:
- my_secret_data
mock-wms-consumer:
image: mockserver/mockserver:mockserver-5.9.0
container_name: mock-wms-consumer
ports:
- 1080:${WMS_MODULE_PORT}
expose:
- ${WMS_MODULE_PORT}
environment:
LOG_LEVEL: "DEBUG"
SERVER_PORT: ${WMS_MODULE_PORT}
JVM_OPTIONS: -Dmockserver.sslSubjectAlternativeNameDomains='org.mock-server.com,mock-server.com'
networks:
default:
ipv4_address: 172.18.1.2
networks:
default:
ipam:
config:
- subnet: 172.18.1.0/24
volumes:
mysql-db: ~
mongo-db: ~
secrets:
my_secret_data:
file: secrets
This diff is collapsed.
curl --location --request POST 'http://localhost:1026/v2/entities/' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": "urn:ngsi-ld:FlowerBed:FlowerBed-345",
"type": "FlowerBed",
"category": {
"type": "Property",
"value": ["urbanTreeSpot"]
},
"soilMoistureVwc": {
"type": "Property",
"value": 0.85
},
"dateLastWatering": {
"type": "Property",
"value": {
"@type": "DateTime",
"@value": "2020-02-11T08:00:00Z"
}
},
"soilTemperature": {
"type": "Property",
"value": 17
},
"address": {
"type": "Property",
"value": {
"addressCountry": "Switzerland",
"streetAddress": "Place de Sardaigne",
"adressLocality": "Carouge",
"type": "PostalAddress"
}
},
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [46.184255,6.1378375]
}
}
}
'
curl --location --request GET 'http://localhost:1026/v2/entities'
echo "\n\nPretty print:\n"
curl --location --request GET 'http://localhost:1026/v2/entities' | python -mjson.tool
curl --request GET 'http://localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345?options=keyValues' | python -mjson.tool
curl --request GET 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc' | python -mjson.tool
curl --request GET 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value' | python -mjson.tool
# this gives same results:
#curl --request GET 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value'
curl --request PUT 'localhost:1026/v2/entities/urn:ngsi-ld:FlowerBed:FlowerBed-345/attrs/soilMoistureVwc/value' -d $(( RANDOM % 10 )) --header 'Content-Type: text/plain'
echo "Nothing to do here. WMS mock server already running in docker, check log with: `docker-compose logs mock-wms-consumer`"
curl -v localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' \
-d @- <<EOF
{
"description": "A subscription to get info about FlowerBed",
"subject": {
"entities": [
{
"id": "urn:ngsi-ld:FlowerBed:FlowerBed-345",
"type": "FlowerBed"
}
],
"condition": {
"attrs": [
"soilMoistureVwc"
]
}
},
"notification": {
"http": {
"url": "http://172.18.1.2:8080/check_if_soilMoistureVwc_is_low"
},
"attrs": [
"soilMoistureVwc"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
curl 'localhost:1026/v2/subscriptions/' | python -mjson.tool
for a more complete explanation of the scripts included here please refer to the [oficial tutorial](https://fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv2/index.html)
secret
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment