{"info":{"_postman_id":"6b14053b-d153-4984-a955-6d4036dd3078","name":"FIWARE IoT Agent","description":"<html><head></head><body><p>This tutorial introduces the concept of an <strong>IoT Agent</strong> and wires up the dummy <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual\">UltraLight 2.0</a> IoT devices created in the\n<a href=\"https://github.com/Fiware/tutorials.IoT-Sensors\">previous tutorial</a> so that measurements can be read \nand commands can be sent using <a href=\"https://fiware.github.io/specifications/OpenAPI/ngsiv2\">NGSI</a> requests sent to the <a href=\"https://fiware-orion.readthedocs.io/en/latest/\">Orion Context Broker</a>.</p>\n<p>The <code>docker-compose</code> files for this tutorial can be found on GitHub: </p>\n<p><img src=\"https://fiware.github.io/tutorials.Historic-Context/icon/GitHub-Mark-32px.png\" alt=\"GitHub\"> <a href=\"https://github.com/Fiware/tutorials.IoT-Agent\">FIWARE 202: Provisioning an IoT Agent</a></p>\n<h1 id=\"what-is-an-iot-agent\">What is an IoT Agent?</h1>\n<blockquote>\n<p>\"In every operation there is an above the line and a below the line.\nAbove the line is what you do by the book. Below the line is how you\ndo the job.\"</p>\n<p>— John le Carré (A Perfect Spy)</p>\n</blockquote>\n<p>An 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.</p>\n<p>The Orion Context Broker exclusively uses <a href=\"https://fiware.github.io/specifications/OpenAPI/ngsiv2\">NGSI</a> requests for all\nof its interactions. Each IoT Agent provides a <strong>North Port</strong> <a href=\"https://fiware.github.io/specifications/OpenAPI/ngsiv2\">NGSI</a>\ninterface which is used for context broker interactions and all interactions beneath this port occur using the <strong>native protocol</strong>\nof the attached devices. </p>\n<p>In 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.</p>\n<p>IoT Agents already exist or are in development for many common transports and protocols. Examples include the following: </p>\n<ul>\n<li><a href=\"http://fiware-iotagent-json.readthedocs.io/en/latest/\">IoTAgent-JSON</a> (HTTP/MQTT transport) - a bridge between an HTTP/MQTT+JSON based protocol and NGSI</li>\n<li><a href=\"http://fiware-iotagent-lwm2m.readthedocs.io/en/latest\">IoTAgent-LWM2M</a>  (CoaP transport) - a bridge between the Lightweight M2M protocol and NGSI</li>\n<li><a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest\">IoTAgent-UL</a> (HTTP/MQTT transport) -  a bridge between the UltraLight2.0 protocol and NGSI </li>\n<li><a href=\"http://fiware-lorawan.readthedocs.io/en/latest\">IoTagent-LoraWAN</a> (CoaP transport) -  a bridge between the LoraWAN protocol and NGSI</li>\n</ul>\n<h2 id=\"southbound-traffic-commands\">Southbound Traffic (Commands)</h2>\n<p>HTTP 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 <strong>commands</strong> made to \nactuator devices which alter the state of the real world by their actions.  </p>\n<p>For example to switch on a real-life UltraLight 2.0 <strong>Smart Lamp</strong> the following interactions would occur:</p>\n<ol>\n<li>An request is sent to the <strong>Context broker</strong> to invoke the <code>on</code> command of the <strong>Smart Lamp</strong> via NGSI</li>\n<li>The <strong>Context Broker</strong> finds the entity within the context and notes that the context provision for this \n  attribute has been delegated to the IoT Agent</li>\n<li>The <strong>Context broker</strong> sends an NGSI request to the North Port of the <strong>IoT Agent</strong> to invoke the command</li>\n<li>The <strong>IoT Agent</strong> receives this Southbound request and converts it to UltraLight 2.0 syntax and passes it on to the <strong>Smart Lamp</strong> </li>\n<li>The <strong>Smart Lamp</strong> switches on the lamp and returns the result of the command to the <strong>IoT Agent</strong> in UltraLight 2.0 syntax</li>\n<li>The <strong>IoT Agent</strong> receives this Northbound request, interprets it and passes the result of the interaction into\n  the context by making an NGSI request to the <strong>Context Broker</strong>.</li>\n<li>The <strong>Context Broker</strong> receives this Northbound request and updates the context with the result of the command.</li>\n</ol>\n<p><img src=\"https://fiware.github.io/tutorials.IoT-Agent/img/command-swimlane.png\" alt=\"\"></p>\n<ul>\n<li>Requests between <strong>User</strong> and <strong>Context Broker</strong>  use NGSI</li>\n<li>Requests between <strong>Context Broker</strong> and <strong>IoT Agent</strong> use NGSI</li>\n<li>Requests between <strong>IoT Agent</strong> and <strong>IoT Device</strong> use native protocols</li>\n<li>Requests between <strong>IoT Device</strong> and <strong>IoT Agent</strong> use native protocols</li>\n<li>Requests between <strong>IoT Agent</strong> and <strong>Context Broker</strong> use NGSI</li>\n</ul>\n<h2 id=\"northbound-traffic-measurements\">Northbound Traffic (Measurements)</h2>\n<p>Requests 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 <strong>measurements</strong> made\nby sensor devices and relays the state of the real world into the context data of the system.</p>\n<p>For example for a real-life <strong>Motion Sensor</strong> to send a count measurement the following interactions would occur:</p>\n<ol>\n<li>A <strong>Motion Sensor</strong> makes a measurement and passes the result to the <strong>IoT Agent</strong></li>\n<li>The <strong>IoT Agent</strong> 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 <strong>Context Broker</strong>.</li>\n<li>The <strong>Context Broker</strong> receives this Northbound request and updates the context with the result of the measurement.</li>\n</ol>\n<p><img src=\"https://fiware.github.io/tutorials.IoT-Agent/img/measurement-swimlane.png\" alt=\"\"></p>\n<ul>\n<li>Requests between <strong>Iot-Device</strong> and <strong>IoT-Agent</strong> use native protocols</li>\n<li>Requests between <strong>Iot-Agent</strong> and <strong>Context-Broker</strong> use NGSI</li>\n</ul>\n<blockquote>\n<p><strong>Note</strong> Other more complex interactions are also possible, but this overview is sufficient to understand the basic\nprinciples of an IoT Agent.</p>\n</blockquote>\n<h2 id=\"common-functionality\">Common Functionality</h2>\n<p>As 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. </p>\n<ul>\n<li>Offering a standard location to listen to device updates</li>\n<li>Offering a standard location to listen to context data updates</li>\n<li>Holding a list of devices and mapping context data attributes to device syntax</li>\n<li>Security Authorization</li>\n</ul>\n<p>This base functionality has been abstracted out into a common <a href=\"https://fiware-iotagent-node-lib.readthedocs.org\">IoT Agent framework library</a></p>\n<h4 id=\"device-monitor\">Device Monitor</h4>\n<p>For 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: <code>http://localhost:3000/device/monitor</code></p>\n<p><img src=\"https://fiware.github.io/tutorials.IoT-Agent/img/device-monitor.png\" alt=\"FIWARE Monitor\"></p>\n<h1 id=\"architecture\">Architecture</h1>\n<p>This application builds on the components created in <a href=\"https://github.com/Fiware/tutorials.Subscriptions/\">previous tutorials</a>. It\nwill make use of two FIWARE components - the <a href=\"https://fiware-orion.readthedocs.io/en/latest/\">Orion Context Broker</a> and the <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/\">IoT Agent for UltraLight 2.0</a>. Usage of the Orion Context Broker is sufficient for an application to qualify as <em>“Powered by FIWARE”</em>.\nBoth the Orion Context Broker and the IoT Agent rely on open source <a href=\"https://www.mongodb.com/\">MongoDB</a> technology to keep persistence of the information they hold. We will also be using the dummy IoT devices created in the <a href=\"https://github.com/Fiware/tutorials.IoT-Sensors/\">previous tutorial</a> </p>\n<p>Therefore the overall architecture will consist of the following elements:</p>\n<ul>\n<li>The FIWARE <a href=\"https://fiware-orion.readthedocs.io/en/latest/\">Orion Context Broker</a> which will receive requests using <a href=\"https://fiware.github.io/specifications/OpenAPI/ngsiv2\">NGSI</a></li>\n<li>The FIWARE <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/\">IoT Agent for UltraLight 2.0</a> which will receive southbound requests using <a href=\"https://fiware.github.io/specifications/OpenAPI/ngsiv2\">NGSI</a> and convert them to  <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual\">UltraLight 2.0</a> commands for the devices</li>\n<li>The underlying <a href=\"https://www.mongodb.com/\">MongoDB</a> database :<ul>\n<li>Used by the <strong>Orion Context Broker</strong> to hold context data information such as data entities, subscriptions and registrations</li>\n<li>Used by the <strong>IoT Agent</strong> to hold device information such as device URLs and Keys</li>\n</ul>\n</li>\n<li>The <strong>Context Provider NGSI</strong> proxy is not used in this tutorial. It does the following:<ul>\n<li>receive requests using <a href=\"https://fiware.github.io/specifications/OpenAPI/ngsiv2\">NGSI</a></li>\n<li>makes requests to publicly available data sources using their own APIs in a proprietory format </li>\n<li>returns context data back to the Orion Context Broker in <a href=\"https://fiware.github.io/specifications/OpenAPI/ngsiv2\">NGSI</a> format.</li>\n</ul>\n</li>\n<li>The <strong>Stock Management Frontend</strong>  is not used in this tutorial will it does the following:<ul>\n<li>Display store information</li>\n<li>Show which products can be bought at each store</li>\n<li>Allow users to \"buy\" products and reduce the stock count.</li>\n</ul>\n</li>\n<li>A webserver acting as set of [dummy IoT devices]](<a href=\"https://github.com/Fiware/tutorials.IoT-Sensors\">https://github.com/Fiware/tutorials.IoT-Sensors</a>) using the <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual\">UltraLight 2.0</a> protocol running over HTTP.</li>\n</ul>\n<p>Since all interactions between the elements are initiated by HTTP requests, the entities can be containerized and run from exposed ports. </p>\n<p><img src=\"https://fiware.github.io/tutorials.IoT-Agent/img/architecture.png\" alt=\"\"></p>\n<p>The necessary configuration information for wiring up the IoT devices and the IoT Agent can be seen in the services section of the associated <code>docker-compose.yml</code>  file:</p>\n<h2 id=\"dummy-iot-devices-configuration\">Dummy IoT Devices Configuration</h2>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-yaml\">  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</code></pre>\n<p>The <code>context-provider</code> container is listening on two ports: </p>\n<ul>\n<li>Port <code>3000</code> is exposed so we can see the web-page displaying the Dummy IoT devices.</li>\n<li>Port <code>3001</code> is exposed purely for tutorial access - so that cUrl or Postman can make UltraLight commands\nwithout being part of the same network.</li>\n</ul>\n<p>The <code>context-provider</code> container is driven by environment variables as shown:</p>\n<div class=\"click-to-expand-wrapper is-table-wrapper\"><table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Value</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>DEBUG</td>\n<td><code>proxy:*</code></td>\n<td>Debug flag used for logging</td>\n</tr>\n<tr>\n<td>PORT</td>\n<td><code>3000</code></td>\n<td>Port used by web-app which displays the dummy device data</td>\n</tr>\n<tr>\n<td>IOTA_HTTP_HOST</td>\n<td><code>iot-agent</code></td>\n<td>The host name of the IoT Agent for UltraLight 2.0 - see below</td>\n</tr>\n<tr>\n<td>IOTA_HTTP_PORT</td>\n<td><code>7896</code></td>\n<td>The port that the IoT Agent for UltraLight 2.0 will be listening on. <code>7896</code> is a common default for UltraLight over HTTP</td>\n</tr>\n<tr>\n<td>DUMMY_DEVICES_PORT</td>\n<td><code>3001</code></td>\n<td>Port used by the dummy IoT devices to receive commands</td>\n</tr>\n<tr>\n<td>DUMMY_DEVICES_API_KEY</td>\n<td><code>4jggokgpepnvsb2uv4s40d59ov</code></td>\n<td>Random security key used for UltraLight interactions - used to ensure the integrity of interactions between the devices and the IoT Agent</td>\n</tr>\n</tbody>\n</table>\n</div><p>The other <code>context-provider</code> container configuration values described in the YAML file are not used in this tutorial.</p>\n<h2 id=\"iot-agent-for-ultralight-20-configuration\">IoT Agent for UltraLight 2.0 Configuration</h2>\n<p>The <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/\">IoT Agent for UltraLight 2.0</a>  can be instantiated within a Docker container. An offical Docker image is available from <a href=\"https://hub.docker.com/r/fiware/iotagent-ul/\">Docker Hub</a> tagged <code>fiware/iotagent-ul</code>. The \nnecessary configuration can be seen below:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-yaml\">  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</code></pre>\n<p>The <code>iot-agent</code> 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: </p>\n<ul>\n<li>Port <code>7896</code> is exposed to receive Ultralight measurements over HTTP from the Dummy IoT devices</li>\n<li>Port <code>4041</code> is exposed purely for tutorial access - so that cUrl or Postman can make provisioning commands\nwithout being part of the same network.</li>\n</ul>\n<p>The <code>iot-agent</code> container is driven by environment variables as shown:</p>\n<div class=\"click-to-expand-wrapper is-table-wrapper\"><table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Value</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>IOTA_CB_HOST</td>\n<td><code>orion</code></td>\n<td>Hostname of the context broker to update context</td>\n</tr>\n<tr>\n<td>IOTA_CB_PORT</td>\n<td><code>1026</code></td>\n<td>Port that context broker listens on to update context</td>\n</tr>\n<tr>\n<td>IOTA_NORTH_PORT</td>\n<td><code>4041</code></td>\n<td>Port used for Configuring the IoT Agent and receiving context updates from the context broker</td>\n</tr>\n<tr>\n<td>IOTA_REGISTRY_TYPE</td>\n<td><code>mongodb</code></td>\n<td>Whether to hold IoT device info in memory or in a database</td>\n</tr>\n<tr>\n<td>IOTA_LOG_LEVEL</td>\n<td><code>DEBUG</code></td>\n<td>The log level of the IoT Agent</td>\n</tr>\n<tr>\n<td>IOTA_TIMESTAMP</td>\n<td><code>true</code></td>\n<td>Whether to supply timestamp information with each measurement received from attached devices</td>\n</tr>\n<tr>\n<td>IOTA_MONGO_HOST</td>\n<td><code>context-db</code></td>\n<td>The host name of mongoDB - used for holding device information</td>\n</tr>\n<tr>\n<td>IOTA_MONGO_PORT</td>\n<td><code>27017</code></td>\n<td>The port mongoDB is listening on</td>\n</tr>\n<tr>\n<td>IOTA_MONGO_DB</td>\n<td><code>iotagentul</code></td>\n<td>The name of the database used in mongoDB</td>\n</tr>\n<tr>\n<td>IOTA_HTTP_PORT</td>\n<td><code>7896</code></td>\n<td>The port where the IoT Agent listens for IoT device traffic over HTTP</td>\n</tr>\n<tr>\n<td>IOTA_PROVIDER_URL</td>\n<td><code>http://iot-agent:4041</code></td>\n<td>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</td>\n</tr>\n</tbody>\n</table>\n</div></body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[{"content":"What is an IoT Agent?","slug":"what-is-an-iot-agent"},{"content":"Architecture","slug":"architecture"}],"owner":"513743","collectionId":"6b14053b-d153-4984-a955-6d4036dd3078","publishedId":"RWgqVJkL","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"EF5B25"},"publishDate":"2020-01-02T11:03:19.000Z"},"item":[{"name":"Connecting IoT Devices","item":[{"name":"IoT Agent - Obtain Version Information","id":"ebbafc67-6d8c-4a98-8dd4-0e86f3909da3","request":{"method":"GET","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:4041/iot/about","description":"<p>Once the IoT Agent is running, You can check the status by making an HTTP request to the exposed port. \nIf the response is blank, this is usually because the MongoDB database holding the context information is not running or not connected.</p>\n<blockquote>\n<p><strong>Troubleshooting:</strong> What if the response is blank ?</p>\n<ul>\n<li>To check that a docker container is running try</li>\n</ul>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-bash\">docker ps\n</code></pre>\n<p>You should see several containers running. If <code>iot-agent</code> is not running, you can restart the containers as necessary.</p>\n</blockquote>\n","urlObject":{"protocol":"http","path":["iot","about"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"ebbafc67-6d8c-4a98-8dd4-0e86f3909da3"},{"name":"IoT Agent - Create a Service Group","id":"ce19cbaf-b6e4-40f9-bf1a-a7d12c86f5a7","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n \"services\": [\n   {\n     \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n     \"cbroker\":     \"http://orion:1026\",\n     \"entity_type\": \"Motion\",\n     \"resource\":    \"/iot/d\"\n   }\n ]\n}"},"url":"http://localhost:4041/iot/services","description":"<p>Invoking group provision is always the the first step in connecting devices since it is always necessary to\nsupply an authentication key with each measurement and the IoT Agent will not initially know which URL \nthe context broker is responding on.</p>\n<p>It is possible to set up default commands and attributes for all devices as well, but this\nis not done within this tutorial as we will be provisioning each device separately.</p>\n<p>This example provisions an anonymous group of devices. It tells the IoT Agent that a series of devices\nwill be sending messages to the <code>IOTA_HTTP_PORT</code> (where the IoT Agent is listening for <strong>Northbound</strong> communications)</p>\n<p>In the example the IoT Agent is informed that the <code>/iot/d</code> endpoint will be used and that devices will authenticate\nthemselves by including the token <code>4jggokgpepnvsb2uv4s40d59ov</code>. For an UltraLight IoT Agent this means devices will\nbe sending GET or POST requests to: </p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code>http://iot-agent:7896/iot/d?i=&lt;device_id&gt;&amp;k=4jggokgpepnvsb2uv4s40d59ov\n</code></pre><p>Which should be familiar UltraLight 2.0 syntax from the previous tutorial.</p>\n<p>When a measurement from an IoT device is received on the resource url it needs to be \ninterpreted and passed to the context broker. The <code>entity_type</code> attribute provides a\ndefault <code>type</code> for each device which has made a  request (in this case anonymous devices\nwill be known as <code>Thing</code> entities. Furthermore the location of the\ncontext broker (<code>cbroker</code>) is needed, so that the IoT Agent can pass on any measurements \nreceived to the  correct URL. <code>cbroker</code> is an optional attribute - if it is not provided, \nthe IoT Agent uses the context broker URL as defined in the configuration file, however\nit has been included here for completeness.</p>\n","urlObject":{"protocol":"http","path":["iot","services"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"ce19cbaf-b6e4-40f9-bf1a-a7d12c86f5a7"},{"name":"IoT Agent - Provision a Sensor","id":"72c6617c-669c-4a16-886c-f55c439d1d81","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n \"devices\": [\n   {\n     \"device_id\":   \"motion001\",\n     \"entity_name\": \"urn:ngsi-ld:Motion:001\",\n     \"entity_type\": \"Motion\",\n     \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n     \"timezone\":    \"Europe/Berlin\",\n     \"attributes\": [\n       { \"object_id\": \"c\", \"name\": \"count\", \"type\": \"Integer\" }\n     ],\n     \"static_attributes\": [\n       { \"name\":\"refStore\", \"type\": \"Relationship\", \"value\": \"urn:ngsi-ld:Store:001\"}\n     ]\n   }\n ]\n}"},"url":"http://localhost:4041/iot/devices","description":"<p>It is common good practice to use URNs following the NGSI-LD <a href=\"https://docbox.etsi.org/ISG/CIM/Open/ISG_CIM_NGSI-LD_API_Draft_for_public_review.pdf\">draft recommendation</a> when creating entities. Furthermore it is easier to understand\nmeaningful names when defining data attributes. These mappings can be defined by provisioning a device individually.</p>\n<p>Three types of meaasurement attributes can be provisioned:</p>\n<ul>\n<li><code>attributes</code> are active readings from the device</li>\n<li><code>lazy</code> attributes are only sent on request -  The IoT Agent will inform the device to return the measurement</li>\n<li><code>static_attributes</code> are as the name suggests static data about the device (such as relationships) passed on \nto the context broker.</li>\n</ul>\n<blockquote>\n<p><strong>Note</strong>: in the case where individual <code>id</code>s are not required, or aggregated data is sufficient \nthe <code>attributes</code> can be defined within the provisioning service rather than individually.</p>\n</blockquote>\n<p>In the request we are assiociating the device <code>motion001</code> with the URN <code>urn:ngsd-ld:Motion:001</code>\nand mapping the device reading <code>c</code> with the context attribute <code>count</code> (which is defined as an <code>Integer</code>)\nA <code>refStore</code> is defined as a <code>static_attribute</code>, placing the device within <strong>Store</strong> <code>urn:ngsi-ld:Store:001</code></p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"72c6617c-669c-4a16-886c-f55c439d1d81"},{"name":"Dummy Device  - Measurement","id":"904e12d5-6bbb-4aff-b716-ebba93c05b8a","request":{"method":"POST","header":[{"key":"Content-Type","value":"text/plain"}],"body":{"mode":"raw","raw":"c|1"},"url":"http://localhost:7896/iot/d?k=4jggokgpepnvsb2uv4s40d59ov&i=motion001","description":"<p>This example simulates a request coming from the device <code>motion001</code></p>\n<p>The request to the previously provisioned resource <code>iot/d</code> is in UltraLight 2.0 format\nand identifies the device <code>motion001</code> and passes a known API key.</p>\n<p>A similar request was made in the previous tutorial (before the IoT Agent was connected)\nwhen the door was unlocked, you will have seen the state of each motion sensor changing\nand a Northbound request will be logged in the device monitor.</p>\n","urlObject":{"protocol":"http","port":"7896","path":["iot","d"],"host":["localhost"],"query":[{"key":"k","value":"4jggokgpepnvsb2uv4s40d59ov"},{"key":"i","value":"motion001"}],"variable":[]}},"response":[],"_postman_id":"904e12d5-6bbb-4aff-b716-ebba93c05b8a"},{"name":"Context Broker - Read the Motion Sensor","id":"b87ee72f-94a1-4b49-aa8c-7fe22cf8dfff","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Motion:001","description":"<p>This example returns the data for the <code>Motion</code> entity with the <code>id=urn:ngsd-ld:Motion:001</code> within the context data.</p>\n<p>The response shows that the device with <code>id=motion001</code> has been successfully identifed by the IoT Agent and mapped to the\nentity <code>id=urn:ngsd-ld:Motion:001</code>. This new entity has been created within the context data. The <code>c</code> \nattribute from the dummy device measurement request has been mapped to the more meaningful <code>count</code> attribute\nwithin the context. As you will notice, a <code>TimeInstant</code> attribute has been added to both the entity and the\nmeta data of the attribute - this represents the last time the entity and attribute have been updated, and is\nautomatically added to each new entity because the <code>IOTA_TIMESTAMP</code>  environment variable was set when the\nIoT Agent was started up. The <code>refStore</code> attribute comes from the <code>static_attributes</code> set when the device was provisioned.</p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Motion:001"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"b87ee72f-94a1-4b49-aa8c-7fe22cf8dfff"},{"name":"IoT Agent - Provision an Actuator","id":"2378972d-87f5-4ac5-bffe-3130b93fde59","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"devices\": [\n    {\n      \"device_id\": \"bell001\",\n      \"entity_name\": \"urn:ngsi-ld:Bell:001\",\n      \"entity_type\": \"Bell\",\n      \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n      \"protocol\": \"PDI-IoTA-UltraLight\",\n      \"transport\": \"HTTP\",\n      \"endpoint\": \"http://context-provider:3001/iot/bell001\",\n      \"commands\": [ \n        {\n          \"name\": \"ring\",\n          \"type\": \"command\"\n        }\n       ],\n       \"static_attributes\": [\n         {\"name\":\"refStore\", \"type\": \"Relationship\",\"value\": \"urn:ngsi-ld:Store:001\"}\n    \t]\n    }\n  ]\n}\n"},"url":"http://localhost:4041/iot/devices","description":"<p>Provisioning an actuator is similar to provisioning a sensor. This time an <code>endpoint</code> attribute holds\nthe location where the IoT Agent needs to send the UltraLight command and the <code>commands</code> array includes\na list of each command that can be invoked. The example below provisions a bell with the <code>deviceId=bell001</code>.\nThe endpoint is <code>http://context-provider:3001/iot/bell001</code> and it can accept the <code>ring</code> command.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"2378972d-87f5-4ac5-bffe-3130b93fde59"},{"name":"IoT Agent - Provision a Bidrectional Attribute","id":"27f05d39-319c-4d1c-8226-6a57bfe00445","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n    \"devices\": [\n        {\n            \"device_id\": \"bell002\",\n            \"entity_name\": \"urn:ngsi-ld:Bell:002\",\n            \"entity_type\": \"Bell\",\n            \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n            \"protocol\": \"PDI-IoTA-UltraLight\",\n            \"transport\": \"HTTP\",\n            \"endpoint\": \"http://context-provider:3001/iot/bell002\",\n            \"attributes\": [\n                {\n                    \"name\": \"ring\",\n                    \"type\": \"Text\",\n                    \"expression\": \"ring\",\n                    \"reverse\": [\n                        {\n                            \"object_id\": \"ring\",\n                            \"type\": \"Text\",\n                            \"expression\": \"ring | toString()\"\n                        }\n                    ]\n                }\n            ],\n            \"static_attributes\": [\n                {\n                    \"name\": \"refStore\",\n                    \"type\": \"Relationship\",\n                    \"value\": \"urn:ngsi-ld:Store:002\"\n                }\n            ]\n        }\n    ]\n}"},"url":"http://localhost:4041/iot/devices","description":"<p>An actuator can also be provisioned using a bidirectional attribute. Once again an <code>endpoint</code> attribute holds\nthe location where the IoT Agent needs to send the UltraLight command. The <code>ring</code> attribute is defined using an <code>expression</code> and mapped to  itself in the <code>reverse</code> direction. When un update to the <code>ring</code> attribute is received, it is also send to the device itself.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"27f05d39-319c-4d1c-8226-6a57bfe00445"},{"name":"IoT Agent - Invoke a Command","id":"d67e26e8-3dc8-41d8-a652-d93c1a6bcd9c","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n    \"actionType\": \"update\",\n    \"entities\": [\n        {\n            \"type\": \"Bell\",\n            \"id\": \"urn:ngsi-ld:Bell:001\",\n            \"ring\" : {\n                \"type\": \"command\",\n                \"value\": \"\"\n            }\n        }\n    ]\n}"},"url":"http://localhost:4041/v2/op/update","description":"<p>Before we wire-up the context broker, we can test that a command can be send to a device by making a REST request \ndirectly to the IoT Agent's North Port using the <code>/v1/updateContext</code> endpoint.\nIt is this endpoint that will eventually be invoked by the context broker once we have connected it up. \nTo test the configuration you can run the command directly as shown.</p>\n<p>If you are viewing the device monitor page, you can also see the state of the bell change.</p>\n<p><img src=\"https://fiware.github.io/tutorials.IoT-Agent/img/bell-ring.gif\" alt /></p>\n","urlObject":{"protocol":"http","path":["v2","op","update"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"d67e26e8-3dc8-41d8-a652-d93c1a6bcd9c"},{"name":"Context Broker - Read the Command Result","id":"ecf5ce9e-8991-4d17-bec0-aa32162113df","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001?options=keyValues","description":"<p>The result of the command to ring the bell can be read by querying the entity within the Orion Context Broker. </p>\n<p>The <code>TimeInstant</code> shows last the time any command associated with the entity has been invoked. the result of <code>ring</code> command can be see in the value of the <code>ring_info</code> attribute</p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Bell:001"],"host":["localhost:1026"],"query":[{"key":"options","value":"keyValues"}],"variable":[]}},"response":[],"_postman_id":"ecf5ce9e-8991-4d17-bec0-aa32162113df"},{"name":"IoT Agent - Provision a Smart Door","id":"65c28ff6-fa4c-4579-a2ae-fc7e384995f3","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"devices\": [\n    {\n      \"device_id\": \"door001\",\n      \"entity_name\": \"urn:ngsi-ld:Door:001\",\n      \"entity_type\": \"Door\",\n      \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n      \"protocol\": \"PDI-IoTA-UltraLight\",\n      \"transport\": \"HTTP\",\n      \"endpoint\": \"http://context-provider:3001/iot/door001\",\n      \"commands\": [ \n        {\"name\": \"unlock\",\"type\": \"command\"},\n        {\"name\": \"open\",\"type\": \"command\"},\n        {\"name\": \"close\",\"type\": \"command\"},\n        {\"name\": \"lock\",\"type\": \"command\"}\n       ],\n       \"attributes\": [\n       \t{\"object_id\": \"s\", \"name\": \"state\", \"type\":\"Text\"}\n       ],\n       \"static_attributes\": [\n         {\"name\":\"refStore\", \"type\": \"Relationship\",\"value\": \"urn:ngsi-ld:Store:001\"}\n       ]\n    }\n  ]\n}\n"},"url":"http://localhost:4041/iot/devices","description":"<p>Provisioning  a device which offers both commands and measurements is merely a matter of making an HTTP POST request\nwith both <code>attributes</code> and <code>command</code> attributes in the body of the request.</p>\n<p>This example provisions a smart door with four commands <code>lock</code>, <code>unlock</code>, <code>open</code> and <code>close</code> and maps a single attribute.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"65c28ff6-fa4c-4579-a2ae-fc7e384995f3"},{"name":"IoT Agent - Provision a Smart Lamp","id":"3867839c-62d7-41e1-90ea-978980f2e57b","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"devices\": [\n    {\n      \"device_id\": \"lamp001\",\n      \"entity_name\": \"urn:ngsi-ld:Lamp:001\",\n      \"entity_type\": \"Lamp\",\n      \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n      \"protocol\": \"PDI-IoTA-UltraLight\",\n      \"transport\": \"HTTP\",\n      \"endpoint\": \"http://context-provider:3001/iot/lamp001\",\n      \"commands\": [ \n        {\"name\": \"on\",\"type\": \"command\"},\n        {\"name\": \"off\",\"type\": \"command\"}\n       ],\n       \"attributes\": [\n       \t{\"object_id\": \"s\", \"name\": \"state\", \"type\":\"Text\"},\n        {\"object_id\": \"l\", \"name\": \"luminosity\", \"type\":\"Integer\"}\n       ],\n       \"static_attributes\": [\n         {\"name\":\"refStore\", \"type\": \"Relationship\",\"value\": \"urn:ngsi-ld:Store:001\"}\n    \t]\n    }\n  ]\n}\n"},"url":"http://localhost:4041/iot/devices","description":"<p>Provisioning  a device which offers both commands and measurements is merely a matter of making an HTTP POST request\nwith both <code>attributes</code> and <code>command</code> attributes in the body of the request.</p>\n<p>This example provisions a smart door with two commands <code>on</code> and <code>off</code> and maps two attributes.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"3867839c-62d7-41e1-90ea-978980f2e57b"},{"name":"IoT Agent - List all Provisioned Devices","id":"198f6a0b-bf95-4a26-b3c1-0b97b2f955d5","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:4041/iot/devices","description":"<p>This example lists all provisioned devices by making a GET request to the <code>/iot/devices</code> endpoint.</p>\n<p>The response includes all the commands and attributes mappings associated with all provisioned IoT devices.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"198f6a0b-bf95-4a26-b3c1-0b97b2f955d5"}],"id":"ab8b5d28-89c4-4a30-a85b-2fbc20d1276f","description":"<p>The IoT Agent acts as a middleware between the IoT devices and the context broker. It therefore\nneeds to be able to create context data entities with unique ids.  Once a service has been provisioned\nand an unknown device makes a measurement the IoT Agent add this to the context using the supplied\n<code>&lt;device-id&gt;</code> (unless the device is recognized and can be mapped to a known id.</p>\n<p>There is no guarantee that every supplied IoT device <code>&lt;device-id&gt;</code> will always be unique, therefore \nall provisioning requests to the IoT Agent require two mandatory headers:</p>\n<ul>\n<li><code>fiware-service</code> header is defined so that entities for a given service can be held in a separate mongoDB database.</li>\n<li><code>fiware-servicepath</code> can be used to differenciate between arrays of devices.</li>\n</ul>\n<p>For example within a smart city application you would expect different <code>fiware-service</code> headers for different\ndepartments (e.g. parks, transport, refuse collection etc.) and each <code>fiware-servicepath</code>  would refer to specific park \nand so on. This would mean that data and devices for each service can be identified and separated as needed, but the\ndata would not be siloed - for example data from a  <strong>Smart Bin</strong> within a park can be combined with the <strong>GPS Unit</strong> \nof a refuse truck to alter the route of the truck in an efficient manner. </p>\n<p>The <strong>Smart Bin</strong> and <strong>GPS Unit</strong> are likely to come from different manufacturers and it cannot be \nguaranteed that that there is no overlap within <code>&lt;device-ids&gt;</code>s used. The use of the  <code>fiware-service</code> and\n<code>fiware-servicepath</code> headers can ensure that this is always the case, and allows the context broker to identify\nthe original source of the context data.</p>\n","event":[{"listen":"prerequest","script":{"id":"661d9977-6eda-41bc-ab3a-5ab127cf21a5","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"1c47421c-2f50-4cee-add5-99cb44744a53","type":"text/javascript","exec":[""]}}],"_postman_id":"ab8b5d28-89c4-4a30-a85b-2fbc20d1276f"},{"name":"Enabling Context Broker Commands","item":[{"name":"Bell Commands","item":[{"name":"Create Bell","id":"65fb7b77-6786-4363-b621-5a641beacbe1","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":"http://localhost:1026/v2/entities","description":"<p>To invoke the <code>open</code> command, the <code>open</code> attribute must be updated in the context.</p>\n","urlObject":{"protocol":"http","path":["v2","entities"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"65fb7b77-6786-4363-b621-5a641beacbe1"},{"name":"Ring Bell","id":"399eb374-bcef-4067-8a6a-5a38294a2e77","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"PATCH","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"ring\": {\n      \"type\" : \"command\",\n      \"value\" : \"\"\n  }\n}"},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001/attrs?type=Bell","description":"<p>To invoke the <code>ring</code> command, the <code>ring</code> attribute must be updated in the context.</p>\n<p>If you are viewing the device monitor page, you can also see the state of the bell change.</p>\n<p><img src=\"https://fiware.github.io/tutorials.IoT-Agent/img/bell-ring.gif\" alt /></p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Bell:001","attrs"],"host":["localhost:1026"],"query":[{"key":"type","value":"Bell"}],"variable":[]}},"response":[],"_postman_id":"399eb374-bcef-4067-8a6a-5a38294a2e77"},{"name":"Bell Status","id":"7406ac26-29ec-4c4f-85d8-9dabeb8fb95e","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":"{\n\t\"ring\": {\n    \t\"type\" : \"command\",\n    \t\"value\" : \"\"\n\t}\n}"},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Bell:001?options=keyValues","description":"<p>The result of the command to ring the bell can be read by querying the entity within the Orion Context Broker. </p>\n<p>The <code>TimeInstant</code> shows last the time any command associated with the entity has been invoked. the result of <code>ring</code> command can be see in the value of the <code>ring_info</code> attribute</p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Bell:001"],"host":["localhost:1026"],"query":[{"key":"options","value":"keyValues"}],"variable":[]}},"response":[],"_postman_id":"7406ac26-29ec-4c4f-85d8-9dabeb8fb95e"}],"id":"f8b5e634-3cef-4b64-b9e3-01ae23b36886","description":"<p>The <strong>Bell</strong> entity has been mapped to <code>id=\"urn:ngsi-ld:Bell:001\"</code> with an entity <code>type=\"Bell\"</code></p>\n","event":[{"listen":"prerequest","script":{"id":"03f1d3da-6cdb-4a0a-bc49-3d970f1c4a06","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"4b157849-2b5c-42a6-b5f3-786fe212a846","type":"text/javascript","exec":[""]}}],"_postman_id":"f8b5e634-3cef-4b64-b9e3-01ae23b36886"},{"name":"Smart Door Commands","item":[{"name":"Create Door","id":"d03db46e-2f6b-4938-89b0-b09400191f1d","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":"http://localhost:1026/v2/entities","description":"<p>To invoke the <code>open</code> command, the <code>open</code> attribute must be updated in the context.</p>\n","urlObject":{"protocol":"http","path":["v2","entities"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"d03db46e-2f6b-4938-89b0-b09400191f1d"},{"name":"Open a Door","id":"6e397349-4e60-41fe-9bb8-559aa54975dc","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"PATCH","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"open\": {\n      \"type\" : \"command\",\n      \"value\" : \"\"\n  }\n}"},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001/attrs?type=Door","description":"<p>To invoke the <code>open</code> command, the <code>open</code> attribute must be updated in the context.</p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Door:001","attrs"],"host":["localhost:1026"],"query":[{"key":"type","value":"Door"}],"variable":[]}},"response":[],"_postman_id":"6e397349-4e60-41fe-9bb8-559aa54975dc"},{"name":"Door Status","id":"ada097ca-ea06-4ce9-a6cb-d4991b0cfe8b","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001?options=keyValues","description":"<p>The result of the invocation of <strong>Smart Door</strong> commands can be read by querying the entity within the Orion Context Broker. </p>\n<p>The <code>TimeInstant</code> shows last the time any command associated with the entity has been invoked. </p>\n<ul>\n<li>The result of <code>open</code> command can be see in the value of the <code>open_info</code> attribute</li>\n<li>The result of <code>close</code> command can be see in the value of the <code>close_info</code> attribute</li>\n<li>The result of <code>lock</code> command can be see in the value of the <code>lock_info</code> attribute</li>\n<li>The result of <code>unlock</code> command can be see in the value of the <code>unlock_info</code> attribute</li>\n</ul>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Door:001"],"host":["localhost:1026"],"query":[{"key":"options","value":"keyValues"}],"variable":[]}},"response":[],"_postman_id":"ada097ca-ea06-4ce9-a6cb-d4991b0cfe8b"}],"id":"bec2fec2-bb27-4932-a3f0-de357bab4566","description":"<p>The <strong>Smart Door</strong> entity has been mapped to <code>id=\"urn:ngsi-ld:Door:001\"</code> with an entity <code>type=\"Door\"</code></p>\n","event":[{"listen":"prerequest","script":{"id":"bd93a337-b87f-4f47-9aca-604325c80bec","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"062e5306-e534-49d9-ac6c-df5d71317195","type":"text/javascript","exec":[""]}}],"_postman_id":"bec2fec2-bb27-4932-a3f0-de357bab4566"},{"name":"Smart Lamp","item":[{"name":"Create Lamp","id":"c21ebf0f-511b-44aa-acb6-c1ce8203544a","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":"http://localhost:1026/v2/entities","description":"<p>To invoke the <code>open</code> command, the <code>open</code> attribute must be updated in the context.</p>\n","urlObject":{"protocol":"http","path":["v2","entities"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"c21ebf0f-511b-44aa-acb6-c1ce8203544a"},{"name":"Switch On a Lamp","id":"cb5ec44e-d9e9-4fe5-a42a-fe0463529664","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"PATCH","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"on\": {\n      \"type\" : \"command\",\n      \"value\" : \"\"\n  }\n}"},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs?type=Lamp","description":"<p>To switch on the <strong>Smart Lamp</strong>, the <code>on</code> attribute must be updated in the context.</p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Lamp:001","attrs"],"host":["localhost:1026"],"query":[{"key":"type","value":"Lamp"}],"variable":[]}},"response":[],"_postman_id":"cb5ec44e-d9e9-4fe5-a42a-fe0463529664"},{"name":"Lamp Status","id":"be5b0812-6955-46b9-91ff-2f09f9f81570","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001?options=keyValues","description":"<p>The result of the invocation of <strong>Smart Lamp</strong> commands can be read by querying the entity within the Orion Context Broker. </p>\n<p>The <code>TimeInstant</code> shows last the time any command associated with the entity has been invoked. </p>\n<ul>\n<li>The result of <code>on</code> command can be see in the value of the <code>on_info</code> attribute</li>\n<li>The result of <code>off</code> command can be see in the value of the <code>off_info</code> attribute</li>\n</ul>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Lamp:001"],"host":["localhost:1026"],"query":[{"key":"options","value":"keyValues"}],"variable":[]}},"response":[],"_postman_id":"be5b0812-6955-46b9-91ff-2f09f9f81570"}],"id":"691b3708-4acb-44d0-b6ef-14bf417e0909","description":"<p>The <strong>Smart Lamp</strong> entity has been mapped to <code>id=\"urn:ngsi-ld:Lamp:001\"</code> with an entity <code>type=\"Lamp\"</code></p>\n","event":[{"listen":"prerequest","script":{"id":"5d5cbd31-cc55-4abd-a3b5-90be1a06ebad","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"aebaf411-d20a-4580-aee9-8484def536ad","type":"text/javascript","exec":[""]}}],"_postman_id":"691b3708-4acb-44d0-b6ef-14bf417e0909"},{"name":"List Provisioned Devices","id":"d6f49c29-cfd3-40ff-9389-87a59c1227ea","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/","description":"<p>This example returns the data of all <code>Store</code> entities within the context data</p>\n","urlObject":{"protocol":"http","path":["v2","entities",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"d6f49c29-cfd3-40ff-9389-87a59c1227ea"}],"id":"f3c4d2b1-d9d8-40df-872c-652ce9b5eae9","description":"<p>Having connected up the IoT Agent to the IoT devices, the Orion Context Broker was informed that the commands are\nnow available. In other words the IoT Agent registered itself as a\n<a href=\"https://github.com/FIWARE/tutorials.Context-Providers/\">Context Provider</a> for the command attributes.</p>\n<p>Once the commands have been registered it will be possible to ring the <strong>Bell</strong>, open and close the <strong>Smart Door</strong> and\nswitch the <strong>Smart Lamp</strong> on and off by sending requests to the Orion Context Broker, rather than sending UltraLight 2.0\nrequests directly t the IoT devices as we did in the <a href=\"https://github.com/Fiware/tutorials.IoT-Sensors\">previous tutorial</a></p>\n","event":[{"listen":"prerequest","script":{"id":"e5aa0b75-9618-464b-9547-bccf5360d530","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"862fb9fb-be99-4b36-bb84-8ec7f5638ede","type":"text/javascript","exec":[""]}}],"_postman_id":"f3c4d2b1-d9d8-40df-872c-652ce9b5eae9"},{"name":"Service Group CRUD Actions","item":[{"name":"Create a Service Group","id":"ce39cdf4-b682-47de-a8ef-688cc46d2d8c","request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n \"services\": [\n   {\n     \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n     \"cbroker\":     \"http://orion:1026\",\n     \"entity_type\": \"Thing\",\n     \"resource\":    \"/iot/d\"\n   }\n ]\n}"},"url":"http://localhost:4041/iot/services","description":"<p>This example provisions an anonymous group of devices. It tells the IoT Agent that a series of devices\nwill be sending messages to the <code>IOTA_HTTP_PORT</code> (where the IoT Agent is listening for <strong>Northbound</strong> communications)</p>\n<p>In the example the IoT Agent is informed that the <code>/iot/d</code> endpoint will be used and that devices will authenticate\nthemselves by including the token <code>4jggokgpepnvsb2uv4s40d59ov</code>.</p>\n","urlObject":{"protocol":"http","path":["iot","services"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"ce39cdf4-b682-47de-a8ef-688cc46d2d8c"},{"name":"Read Service Group details","id":"52961794-e69b-4262-a793-d8c6c1286ac4","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","name":"Content-Type","value":"application/x-www-form-urlencoded","type":"text"}],"url":"http://localhost:4041/iot/services?resource=/iot/d","description":"<p>This example obtains the full details of a provisioned services with a given <code>resource</code> path.</p>\n<p>The response includes all the defaults associated with the service group such as the <code>entity_type</code> and any default commands or attribute mappings.</p>\n<p>Service group details can be read by making a GET request to the <code>/iot/services</code> endpoint and providing a <code>resource</code> parameter.</p>\n","urlObject":{"protocol":"http","path":["iot","services"],"host":["localhost:4041"],"query":[{"key":"resource","value":"/iot/d"}],"variable":[]}},"response":[],"_postman_id":"52961794-e69b-4262-a793-d8c6c1286ac4"},{"name":"List all Service Groups","id":"0b08bb82-ff91-4aaa-beeb-e69ee4be18e9","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:4041/iot/services","description":"<p>This example lists all provisioned services by making a GET request to the <code>/iot/services/</code> endpoint.</p>\n<p>The response includes all the defaults associated with each service group such as the <code>entity_type</code> and any default commands or attribute mappings.</p>\n","urlObject":{"protocol":"http","path":["iot","services"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"0b08bb82-ff91-4aaa-beeb-e69ee4be18e9"},{"name":"Update a Service Group","id":"63735be7-3bf5-4b7b-85b7-0a7cdd6d1abf","request":{"method":"PUT","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"entity_type\": \"IoT-Device\"\n}"},"url":"http://localhost:4041/iot/services?resource=/iot/d&apikey=4jggokgpepnvsb2uv4s40d59ov","description":"<p>This example updates an existing service group with a given <code>resource</code> path and <code>apikey</code></p>\n<p>Service group details can be updated by making a PUT request to the <code>/iot/services</code> endpoint \nand providing a <code>resource</code> and <code>apikey</code> parameters.</p>\n","urlObject":{"protocol":"http","path":["iot","services"],"host":["localhost:4041"],"query":[{"key":"resource","value":"/iot/d"},{"key":"apikey","value":"4jggokgpepnvsb2uv4s40d59ov"}],"variable":[]}},"response":[],"_postman_id":"63735be7-3bf5-4b7b-85b7-0a7cdd6d1abf"},{"name":"Delete a Service Group","id":"78c8a1c0-eec7-484c-98b3-cd706d85aab6","request":{"method":"DELETE","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:4041/iot/services/?resource=/iot/d&apikey=4jggokgpepnvsb2uv4s40d59ov","description":"<p>This example removes a provisioned service group by making a DELETE request to the <code>/iot/services/</code> endpoint.</p>\n<p>It means that requests to <code>http://iot-agent:7896/iot/d?i=&lt;device_id&gt;&amp;k=4jggokgpepnvsb2uv4s40d59ov</code>\n(where the IoT Agent is listening for <strong>Northbound</strong> communications) should no longer be processed by the IoT Agent. \nThe <code>apiKey</code> and <code>resource</code> parameters must be supplied in order to identify the service group to be deleted.</p>\n","urlObject":{"protocol":"http","path":["iot","services",""],"host":["localhost:4041"],"query":[{"description":{"content":"<p>The path that the IoT Agent had been listening on</p>\n","type":"text/plain"},"key":"resource","value":"/iot/d"},{"key":"apikey","value":"4jggokgpepnvsb2uv4s40d59ov"}],"variable":[]}},"response":[],"_postman_id":"78c8a1c0-eec7-484c-98b3-cd706d85aab6"}],"id":"407d44b0-36af-4097-ba21-4444a7892466","description":"<p>The <strong>CRUD</strong> operations for a service group map on to the expected HTTP verbs under the <code>/iot/services</code> endpoint</p>\n<ul>\n<li><strong>Create</strong> - HTTP POST</li>\n<li><strong>Read</strong> - HTTP GET</li>\n<li><strong>Update</strong> - HTTP PUT</li>\n<li><strong>Delete</strong> - HTTP DELETE</li>\n</ul>\n<p>Use the <code>resource</code> and <code>apikey</code> parameters to uniquely identify a service group.</p>\n","event":[{"listen":"prerequest","script":{"id":"a263bbb6-49c9-404b-8083-c75c37f2fc09","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"c52a2169-d0c9-40b6-a77d-87b94b26db01","type":"text/javascript","exec":[""]}}],"_postman_id":"407d44b0-36af-4097-ba21-4444a7892466"},{"name":"Device CRUD Actions","item":[{"name":"Create a Provisioned Device","id":"e088f761-1881-4560-92ac-4d01d9e1bfe1","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n    \"devices\": [\n        {\n            \"device_id\": \"bell002\",\n            \"entity_name\": \"urn:ngsi-ld:Bell:002\",\n            \"entity_type\": \"Bell\",\n            \"apikey\": \"4jggokgpepnvsb2uv4s40d59ov\",\n            \"protocol\": \"PDI-IoTA-UltraLight\",\n            \"transport\": \"HTTP\",\n            \"endpoint\": \"http://context-provider:3001/iot/bell002\",\n            \"commands\": [\n                {\n                    \"name\": \"ring\",\n                    \"type\": \"command\"\n                }\n            ],\n            \"static_attributes\": [\n                {\n                    \"name\": \"refStore\",\n                    \"type\": \"Relationship\",\n                    \"value\": \"urn:ngsi-ld:Store:002\"\n                }\n            ]\n        }\n    ]\n}"},"url":"http://localhost:4041/iot/devices","description":"<p>This example provisions an individual device. It maps the <code>device_id=bell002</code> to the entity URN <code>urn:ngsi-ld:Bell:002</code> and gives the\nentity a type <code>Bell</code>. The IoT Agent has been informed that the device offers a single <code>ring</code> <code>command</code> and is listening on \n<code>http://context-provider:3001/iot/bell002</code> using HTTP. <code>attributes</code>, <code>lazy</code> attributes and <code>static_attributes</code> can also be provisioned.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"e088f761-1881-4560-92ac-4d01d9e1bfe1"},{"name":"Read Provisioned Device Details","id":"92eaeed4-8e9a-4bbc-a65e-39340a62592b","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:4041/iot/devices/bell002","description":"<p>This example obtains the full details of a provisioned device with a given <code>&lt;device-id&gt;</code> path.</p>\n<p>The response includes all the commands and attributes mappings associated with the device</p>\n<p>Provisioned Device details can be read by making a GET request to the <code>/iot/devices/&lt;device-id&gt;</code> endpoint.</p>\n","urlObject":{"protocol":"http","path":["iot","devices","bell002"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"92eaeed4-8e9a-4bbc-a65e-39340a62592b"},{"name":"List all Provisioned Devices","id":"f80654a3-ef75-4f3d-aa64-b0abb573a8d6","request":{"method":"GET","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:4041/iot/devices","description":"<p>This example lists all provisioned devices by making a GET request to the <code>/iot/devices</code> endpoint.</p>\n<p>The response includes all the commands and attributes mappings associated with all devices</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"f80654a3-ef75-4f3d-aa64-b0abb573a8d6"},{"name":"Update a Provisioned Device","id":"6aead855-aa74-429d-afd7-b8f6ae3943c0","request":{"method":"PUT","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"entity_name\": \"urn:ngsi-ld:Thing:bell002\"\n}"},"url":"http://localhost:4041/iot/devices/bell002","description":"<p>This example updates an existing provisioned device by making a PUT request to the <code>/iot/devices/&lt;device-id&gt;</code> endpoint.</p>\n","urlObject":{"protocol":"http","path":["iot","devices","bell002"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"6aead855-aa74-429d-afd7-b8f6ae3943c0"},{"name":"Delete a Provisioned Device","id":"ef73bac0-505f-4966-9714-c3a1e9ab7b63","request":{"method":"DELETE","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":""},"url":"http://localhost:4041/iot/devices/bell002","description":"<p>This example removes a provisioned device by making a DELETE request to the <code>/iot/services/&lt;device-id&gt;</code> endpoint.</p>\n<p>The device attributes will no longer be mapped and commands can no longer be sent to the device.\nIf the device is making active measurements, they will still be handled with default values\nif the associated service has not been deleted.</p>\n","urlObject":{"protocol":"http","path":["iot","devices","bell002"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"ef73bac0-505f-4966-9714-c3a1e9ab7b63"}],"id":"18700aa1-1aa6-42f6-b9d1-5b4e5e8ec8dc","description":"<p>The <strong>CRUD</strong> operations for an individual device map on to the expected HTTP verbs under the <code>/iot/devices</code> endpoint</p>\n<ul>\n<li><strong>Create</strong> - HTTP POST</li>\n<li><strong>Read</strong> - HTTP GET</li>\n<li><strong>Update</strong> - HTTP PUT</li>\n<li><strong>Delete</strong> - HTTP DELETE</li>\n</ul>\n<p>Use the <code>&lt;device-id&gt;</code> to uniquely identify a device.</p>\n","event":[{"listen":"prerequest","script":{"id":"7d9ab7f8-ffa3-41ac-a686-e74ec2295c42","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"c2f51cc7-59c3-42f5-806b-5d7d87d0125c","type":"text/javascript","exec":[""]}}],"_postman_id":"18700aa1-1aa6-42f6-b9d1-5b4e5e8ec8dc"}],"event":[{"listen":"prerequest","script":{"id":"e64b3c59-ab46-46cf-b504-30a027ca2986","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"04676146-332d-41b3-a65e-b9fd5a527aca","type":"text/javascript","exec":[""]}}],"variable":[{"key":"iot-agent","value":"localhost:4041"},{"key":"orion","value":"localhost:1026"},{"key":"ultralight","value":"localhost:3001"}]}