diff --git a/FIWARE IoT Agent.postman_collection.json b/FIWARE IoT Agent.postman_collection.json index c5ae6c7..b9ecf43 100644 --- a/FIWARE IoT Agent.postman_collection.json +++ b/FIWARE IoT Agent.postman_collection.json @@ -5,7 +5,7 @@ "description": "This tutorial introduces the concept of an **IoT Agent** and wires up the dummy [UltraLight 2.0](http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) IoT devices created in the\n[previous tutorial](https://github.com/Fiware/tutorials.IoT-Sensors) so that measurements can be read \nand commands can be sent using [NGSI](https://fiware.github.io/specifications/OpenAPI/ngsiv2) requests sent to the [Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/).\n\nThe `docker-compose` files for this tutorial can be found on GitHub: \n\n![GitHub](https://fiware.github.io/tutorials.Historic-Context/icon/GitHub-Mark-32px.png) [FIWARE 202: Provisioning an IoT Agent](https://github.com/Fiware/tutorials.IoT-Agent)\n\n# What is an IoT Agent?\n\n> \"In every operation there is an above the line and a below the line.\n> Above the line is what you do by the book. Below the line is how you\n> do the job.\"\n>\n> — John le Carré (A Perfect Spy)\n\nAn IoT Agent is a component that lets a group of devices send their data to and be managed from a Context Broker\nusing their own native protocols. IoT Agents should also be able to deal with security aspects of the Fiware \nplatform (authentication and authorization of the channel) and provide other common services to the device programmer.\n\nThe Orion Context Broker exclusively uses [NGSI](https://fiware.github.io/specifications/OpenAPI/ngsiv2) requests for all\nof its interactions. Each IoT Agent provides a **North Port** [NGSI](https://fiware.github.io/specifications/OpenAPI/ngsiv2)\ninterface which is used for context broker interactions and all interactions beneath this port occur using the **native protocol**\nof the attached devices. \n\nIn effect, this brings a standard interface to all IoT interactions at the context information management level. \nEach group of IoT devices are able to use their own propriatory protocols and disparate transport mechanisms under\nthe hood whilst the associated IoT Agent offers a facade pattern to handle this complexity.\n\nIoT Agents already exist or are in development for many common transports and protocols. Examples include the following: \n\n* [IoTAgent-JSON](http://fiware-iotagent-json.readthedocs.io/en/latest/) (HTTP/MQTT transport) - a bridge between an HTTP/MQTT+JSON based protocol and NGSI\n* [IoTAgent-LWM2M](http://fiware-iotagent-lwm2m.readthedocs.io/en/latest) (CoaP transport) - a bridge between the Lightweight M2M protocol and NGSI\n* [IoTAgent-UL](http://fiware-iotagent-ul.readthedocs.io/en/latest) (HTTP/MQTT transport) - a bridge between the UltraLight2.0 protocol and NGSI \n* [IoTagent-LoraWAN](http://fiware-lorawan.readthedocs.io/en/latest) (CoaP transport) - a bridge between the LoraWAN protocol and NGSI\n\n## Southbound Traffic (Commands)\n\nHTTP requests generated by the from the Context Broker and passed downwards towards an IoT device (via\nan IoT agent) are known as southbound traffic. Southbound traffic consists of **commands** made to \nactuator devices which alter the state of the real world by their actions. \n\nFor example to switch on a real-life UltraLight 2.0 **Smart Lamp** the following interactions would occur:\n\n1. An request is sent to the **Context broker** to invoke the `on` command of the **Smart Lamp** via NGSI\n2. The **Context Broker** finds the entity within the context and notes that the context provision for this \n attribute has been delegated to the IoT Agent\n3. The **Context broker** sends an NGSI request to the North Port of the **IoT Agent** to invoke the command\n4. The **IoT Agent** receives this Southbound request and converts it to UltraLight 2.0 syntax and passes it on to the **Smart Lamp** \n5. The **Smart Lamp** switches on the lamp and returns the result of the command to the **IoT Agent** in UltraLight 2.0 syntax\n6. The **IoT Agent** receives this Northbound request, interprets it and passes the result of the interaction into\n the context by making an NGSI request to the **Context Broker**.\n6. The **Context Broker** receives this Northbound request and updates the context with the result of the command.\n\n\n![](https://fiware.github.io/tutorials.IoT-Agent/img/command-swimlane.png)\n\n* Requests between **User** and **Context Broker** use NGSI\n* Requests between **Context Broker** and **IoT Agent** use NGSI\n* Requests between **IoT Agent** and **IoT Device** use native protocols\n* Requests between **IoT Device** and **IoT Agent** use native protocols\n* Requests between **IoT Agent** and **Context Broker** use NGSI\n\n\n## Northbound Traffic (Measurements)\n\nRequests generated from an IoT device and passed back upwards towards the Context Broker (via an \nIoT agent) are known as northbound traffic. Northbound traffic consists of **measurements** made\nby sensor devices and relays the state of the real world into the context data of the system.\n\nFor example for a real-life **Motion Sensor** to send a count measurement the following interactions would occur:\n\n1. A **Motion Sensor** makes a measurement and passes the result to the **IoT Agent**\n2. The **IoT Agent** receives this Northbound request, converts the result from UltraLight syntax\n and passes the result of the interaction into the context by making an NGSI request to the **Context Broker**.\n3. The **Context Broker** receives this Northbound request and updates the context with the result of the measurement. \n\n\n![](https://fiware.github.io/tutorials.IoT-Agent/img/measurement-swimlane.png)\n\n* Requests between **Iot-Device** and **IoT-Agent** use native protocols\n* Requests between **Iot-Agent** and **Context-Broker** use NGSI\n\n> **Note** Other more complex interactions are also possible, but this overview is sufficient to understand the basic\n> principles of an IoT Agent.\n\n## Common Functionality\n\nAs can be seen from the previous sections, although each IoT Agent will be unique since they interpret different\nprotocols, there will a large degree of similarity between IoT agents. \n\n* Offering a standard location to listen to device updates\n* Offering a standard location to listen to context data updates\n* Holding a list of devices and mapping context data attributes to device syntax\n* Security Authorization\n\nThis base functionality has been abstracted out into a common [IoT Agent framework library](https://fiware-iotagent-node-lib.readthedocs.org)\n\n#### Device Monitor\n\nFor the purpose of this tutorial, a series of dummy IoT devices have been created, which will be attached to the context broker.\nThe state of each device can be seen on the UltraLight device monitor web-page found at: `http://localhost:3000/device/monitor`\n\n![FIWARE Monitor](https://fiware.github.io/tutorials.IoT-Agent/img/device-monitor.png)\n\n# Architecture\n\nThis application builds on the components created in [previous tutorials](https://github.com/Fiware/tutorials.Subscriptions/). It\nwill make use of two FIWARE components - the [Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/) and the [IoT Agent for UltraLight 2.0](http://fiware-iotagent-ul.readthedocs.io/en/latest/). Usage of the Orion Context Broker is sufficient for an application to qualify as *“Powered by FIWARE”*.\nBoth the Orion Context Broker and the IoT Agent rely on open source [MongoDB](https://www.mongodb.com/) technology to keep persistence of the information they hold. We will also be using the dummy IoT devices created in the [previous tutorial](https://github.com/Fiware/tutorials.IoT-Sensors/) \n\n\nTherefore the overall architecture will consist of the following elements:\n\n* The FIWARE [Orion Context Broker](https://fiware-orion.readthedocs.io/en/latest/) which will receive requests using [NGSI](https://fiware.github.io/specifications/OpenAPI/ngsiv2)\n* The FIWARE [IoT Agent for UltraLight 2.0](http://fiware-iotagent-ul.readthedocs.io/en/latest/) which will receive southbound requests using [NGSI](https://fiware.github.io/specifications/OpenAPI/ngsiv2) and convert them to [UltraLight 2.0](http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) commands for the devices\n* The underlying [MongoDB](https://www.mongodb.com/) database :\n + Used by the **Orion Context Broker** to hold context data information such as data entities, subscriptions and registrations\n + Used by the **IoT Agent** to hold device information such as device URLs and Keys\n* The **Context Provider NGSI** proxy is not used in this tutorial. It does the following:\n + receive requests using [NGSI](https://fiware.github.io/specifications/OpenAPI/ngsiv2)\n + makes requests to publicly available data sources using their own APIs in a proprietory format \n + returns context data back to the Orion Context Broker in [NGSI](https://fiware.github.io/specifications/OpenAPI/ngsiv2) format.\n* The **Stock Management Frontend** is not used in this tutorial will it does the following:\n + Display store information\n + Show which products can be bought at each store\n + Allow users to \"buy\" products and reduce the stock count.\n* A webserver acting as set of [dummy IoT devices]](https://github.com/Fiware/tutorials.IoT-Sensors) using the [UltraLight 2.0](http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual) protocol running over HTTP.\n\nSince all interactions between the elements are initiated by HTTP requests, the entities can be containerized and run from exposed ports. \n\n![](https://fiware.github.io/tutorials.IoT-Agent/img/architecture.png)\n\nThe necessary configuration information for wiring up the IoT devices and the IoT Agent can be seen in the services section of the associated `docker-compose.yml` file:\n\n## Dummy IoT Devices Configuration\n\n```yaml\n context-provider:\n image: fiware/cp-web-app:latest\n hostname: context-provider\n container_name: context-provider\n networks:\n - default\n expose:\n - \"3000\"\n - \"3001\"\n ports:\n - \"3000:3000\"\n - \"3001:3001\"\n environment:\n - \"DEBUG=proxy:*\"\n - \"PORT=3000\"\n - \"IOTA_HTTP_HOST=iot-agent\"\n - \"IOTA_HTTP_PORT=7896\"\n - \"DUMMY_DEVICES_PORT=3001\"\n - \"DUMMY_DEVICES_API_KEY=4jggokgpepnvsb2uv4s40d59ov\"\n```\n\nThe `context-provider` container is listening on two ports: \n\n* Port `3000` is exposed so we can see the web-page displaying the Dummy IoT devices.\n* Port `3001` is exposed purely for tutorial access - so that cUrl or Postman can make UltraLight commands\n without being part of the same network.\n\n\nThe `context-provider` container is driven by environment variables as shown:\n\n| Key |Value|Description|\n|-----|-----|-----------|\n|DEBUG|`proxy:*`| Debug flag used for logging |\n|PORT|`3000`|Port used by web-app which displays the dummy device data |\n|IOTA_HTTP_HOST|`iot-agent`| The host name of the IoT Agent for UltraLight 2.0 - see below | \n|IOTA_HTTP_PORT|`7896` | The port that the IoT Agent for UltraLight 2.0 will be listening on. `7896` is a common default for UltraLight over HTTP |\n|DUMMY_DEVICES_PORT|`3001`|Port used by the dummy IoT devices to receive commands |\n|DUMMY_DEVICES_API_KEY|`4jggokgpepnvsb2uv4s40d59ov`| Random security key used for UltraLight interactions - used to ensure the integrity of interactions between the devices and the IoT Agent |\n\nThe other `context-provider` container configuration values described in the YAML file are not used in this tutorial.\n\n## IoT Agent for UltraLight 2.0 Configuration\n\nThe [IoT Agent for UltraLight 2.0](http://fiware-iotagent-ul.readthedocs.io/en/latest/) can be instantiated within a Docker container. An offical Docker image is available from [Docker Hub](https://hub.docker.com/r/fiware/iotagent-ul/) tagged `fiware/iotagent-ul`. The \nnecessary configuration can be seen below:\n\n```yaml\n iot-agent:\n image: fiware/iotagent-ul:latest\n hostname: iot-agent\n container_name: iot-agent\n depends_on:\n - context-db\n - orion\n networks:\n - default\n expose:\n - \"4041\"\n - \"7896\"\n ports:\n - \"4041:4041\"\n - \"7896:7896\"\n environment:\n - \"IOTA_CB_HOST=orion\"\n - \"IOTA_CB_PORT=1026\"\n - \"IOTA_NORTH_PORT=4041\"\n - \"IOTA_REGISTRY_TYPE=mongodb\"\n - \"IOTA_LOG_LEVEL=DEBUG\"\n - \"IOTA_TIMESTAMP=true\"\n - \"IOTA_MONGO_HOST=context-db\"\n - \"IOTA_MONGO_PORT=27017\"\n - \"IOTA_MONGO_DB=iotagentul\"\n - \"IOTA_HTTP_PORT=7896\"\n - \"IOTA_PROVIDER_URL=http://iot-agent:4041\"\n```\n\nThe `iot-agent` container relies on the precence of the Orion Context Broker and uses a MongoDB database to hold device information such as device URLs and Keys. The container is listening on two ports: \n\n* Port `7896` is exposed to receive Ultralight measurements over HTTP from the Dummy IoT devices\n* Port `4041` is exposed purely for tutorial access - so that cUrl or Postman can make provisioning commands\n without being part of the same network.\n\n\nThe `iot-agent` container is driven by environment variables as shown:\n\n| Key |Value|Description|\n|-----|-----|-----------|\n|IOTA_CB_HOST|`orion`| Hostname of the context broker to update context |\n|IOTA_CB_PORT|`1026`| Port that context broker listens on to update context |\n|IOTA_NORTH_PORT|`4041` | Port used for Configuring the IoT Agent and receiving context updates from the context broker |\n|IOTA_REGISTRY_TYPE|`mongodb`| Whether to hold IoT device info in memory or in a database |\n|IOTA_LOG_LEVEL|`DEBUG`|The log level of the IoT Agent |\n|IOTA_TIMESTAMP|`true`| Whether to supply timestamp information with each measurement received from attached devices |\n|IOTA_MONGO_HOST|`context-db`| The host name of mongoDB - used for holding device information |\n|IOTA_MONGO_PORT|`27017`| The port mongoDB is listening on |\n|IOTA_MONGO_DB|`iotagentul`| The name of the database used in mongoDB |\n|IOTA_HTTP_PORT|`7896`| The port where the IoT Agent listens for IoT device traffic over HTTP |\n|IOTA_PROVIDER_URL|`http://iot-agent:4041`| URL passed to the Context Broker when commands are registered, used as a forwarding URL location when the Context Broker issues a command to a device | ", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", "_exporter_id": "513743", - "_collection_link": "https://fiware.postman.co/workspace/NGSI-v2-Tutorials~56ef8b2e-ab05-408c-bbe9-7714cfe08cf6/collection/513743-6b14053b-d153-4984-a955-6d4036dd3078?action=share&creator=513743&source=collection_link" + "_collection_link": "https://fiware.postman.co/workspace/NGSI-v2-Tutorials~56ef8b2e-ab05-408c-bbe9-7714cfe08cf6/collection/513743-6b14053b-d153-4984-a955-6d4036dd3078?action=share&source=collection_link&creator=513743" }, "item": [ { @@ -467,6 +467,43 @@ { "name": "Bell Commands", "item": [ + { + "name": "Create Bell", + "request": { + "method": "POST", + "header": [ + { + "key": "fiware-service", + "value": "openiot" + }, + { + "key": "fiware-servicepath", + "value": "/" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": \"urn:ngsi-ld:Bell:001\",\n \"type\": \"Bell\"\n}" + }, + "url": { + "raw": "http://{{orion}}/v2/entities", + "protocol": "http", + "host": [ + "{{orion}}" + ], + "path": [ + "v2", + "entities" + ] + }, + "description": "To invoke the `open` command, the `open` attribute must be updated in the context." + }, + "response": [] + }, { "name": "Ring Bell", "request": { @@ -490,7 +527,7 @@ "raw": "{\n \"ring\": {\n \"type\" : \"command\",\n \"value\" : \"\"\n }\n}" }, "url": { - "raw": "http://{{orion}}/v2/entities/urn:ngsi-ld:Bell:001/attrs", + "raw": "http://{{orion}}/v2/entities/urn:ngsi-ld:Bell:001/attrs?type=Bell", "protocol": "http", "host": [ "{{orion}}" @@ -500,6 +537,12 @@ "entities", "urn:ngsi-ld:Bell:001", "attrs" + ], + "query": [ + { + "key": "type", + "value": "Bell" + } ] }, "description": "To invoke the `ring` command, the `ring` attribute must be updated in the context.\n\nIf you are viewing the device monitor page, you can also see the state of the bell change.\n\n![](https://fiware.github.io/tutorials.IoT-Agent/img/bell-ring.gif)" @@ -572,6 +615,43 @@ { "name": "Smart Door Commands", "item": [ + { + "name": "Create Door", + "request": { + "method": "POST", + "header": [ + { + "key": "fiware-service", + "value": "openiot" + }, + { + "key": "fiware-servicepath", + "value": "/" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": \"urn:ngsi-ld:Door:001\",\n \"type\": \"Door\"\n}" + }, + "url": { + "raw": "http://{{orion}}/v2/entities", + "protocol": "http", + "host": [ + "{{orion}}" + ], + "path": [ + "v2", + "entities" + ] + }, + "description": "To invoke the `open` command, the `open` attribute must be updated in the context." + }, + "response": [] + }, { "name": "Open a Door", "request": { @@ -595,7 +675,7 @@ "raw": "{\n \"open\": {\n \"type\" : \"command\",\n \"value\" : \"\"\n }\n}" }, "url": { - "raw": "http://{{orion}}/v2/entities/urn:ngsi-ld:Door:001/attrs", + "raw": "http://{{orion}}/v2/entities/urn:ngsi-ld:Door:001/attrs?type=Door", "protocol": "http", "host": [ "{{orion}}" @@ -605,6 +685,12 @@ "entities", "urn:ngsi-ld:Door:001", "attrs" + ], + "query": [ + { + "key": "type", + "value": "Door" + } ] }, "description": "To invoke the `open` command, the `open` attribute must be updated in the context." @@ -677,6 +763,43 @@ { "name": "Smart Lamp", "item": [ + { + "name": "Create Lamp", + "request": { + "method": "POST", + "header": [ + { + "key": "fiware-service", + "value": "openiot" + }, + { + "key": "fiware-servicepath", + "value": "/" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": \"urn:ngsi-ld:Lamp:001\",\n \"type\": \"Lamp\"\n}" + }, + "url": { + "raw": "http://{{orion}}/v2/entities", + "protocol": "http", + "host": [ + "{{orion}}" + ], + "path": [ + "v2", + "entities" + ] + }, + "description": "To invoke the `open` command, the `open` attribute must be updated in the context." + }, + "response": [] + }, { "name": "Switch On a Lamp", "request": { @@ -700,7 +823,7 @@ "raw": "{\n \"on\": {\n \"type\" : \"command\",\n \"value\" : \"\"\n }\n}" }, "url": { - "raw": "http://{{orion}}/v2/entities/urn:ngsi-ld:Lamp:001/attrs", + "raw": "http://{{orion}}/v2/entities/urn:ngsi-ld:Lamp:001/attrs?type=Lamp", "protocol": "http", "host": [ "{{orion}}" @@ -710,6 +833,12 @@ "entities", "urn:ngsi-ld:Lamp:001", "attrs" + ], + "query": [ + { + "key": "type", + "value": "Lamp" + } ] }, "description": "To switch on the **Smart Lamp**, the `on` attribute must be updated in the context." diff --git a/README.ja.md b/README.ja.md index 992ed70..da2b272 100644 --- a/README.ja.md +++ b/README.ja.md @@ -1051,7 +1051,7 @@ IoT Agent を IoT デバイスに接続すると、Orion Context Broker にコ ```console curl -iX PATCH \ - 'http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001/attrs' \ + 'http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001/attrs?type=Bell' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ -H 'fiware-servicepath: /' \ @@ -1078,7 +1078,7 @@ curl -iX PATCH \ ```console curl -iX PATCH \ - 'http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001/attrs' \ + 'http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001/attrs?type=Door' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ -H 'fiware-servicepath: /' \ @@ -1101,7 +1101,7 @@ curl -iX PATCH \ ```console curl -iX PATCH \ - 'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs' \ + 'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs?type=Lamp' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ -H 'fiware-servicepath: /' \ diff --git a/README.md b/README.md index 4066d4a..88d98df 100644 --- a/README.md +++ b/README.md @@ -918,6 +918,12 @@ switch the **Smart Lamp** on and off by sending requests to the Orion Context Br requests directly the IoT devices as we did in the [previous tutorial](https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-v2) +> ![NOTE] +> If the device is provisioned, but no data concerning the Entity is present in the context yet, the invocation must +> include the `type` of the Entity to succeed. However if the Entity `type` is already known +> to the broker, this hint +> is not necessary. This is because the registration is matched on both `id` and `type`. + ### Ringing the Bell To invoke the `ring` command, the `ring` attribute must be updated in the context. @@ -926,7 +932,7 @@ To invoke the `ring` command, the `ring` attribute must be updated in the contex ```console curl -iX PATCH \ - 'http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001/attrs' \ + 'http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001/attrs?type=Bell' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ -H 'fiware-servicepath: /' \ @@ -950,7 +956,7 @@ To invoke the `open` command, the `open` attribute must be updated in the contex ```console curl -iX PATCH \ - 'http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001/attrs' \ + 'http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001/attrs?type=Door' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ -H 'fiware-servicepath: /' \ @@ -970,7 +976,7 @@ To switch on the **Smart Lamp**, the `on` attribute must be updated in the conte ```console curl -iX PATCH \ - 'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs' \ + 'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs?type=Lamp' \ -H 'Content-Type: application/json' \ -H 'fiware-service: openiot' \ -H 'fiware-servicepath: /' \