{"info":{"_postman_id":"fddcfd01-0c04-4da3-bc34-2ad6ff9fbf0e","name":"FIWARE IoT over MQTT","description":"<html><head></head><body><p>This tutorial uses introduces the use of the MQTT protocol across IoT devices connecting to FIWARE. The <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual\">UltraLight 2.0</a> IoT Agent\ncreated in the <a href=\"https://github.com/Fiware/tutorials.IoT-Agent\">previous tutorial</a> is reconfigured to\ncommunicate with a set of dummy IoT devices using MQTT</p>\n<h1 id=\"what-is-mqtt\">What is MQTT?</h1>\n<p>MQTT is publish-subscribe-based messaging protocol used in the Internet of Things. It works on top of the TCP/IP\nprotocol, and is designed for connections with remote locations where a \"small code footprint\" is required or the\nnetwork bandwidth is limited. The goal is to provide a protocol, which is bandwidth-efficient and uses little\nbattery power.</p>\n<p>The <a href=\"https://github.com/Fiware/tutorials.IoT-Agent\">previous tutorial</a> used HTTP as its transport mechanism between\nthe devices and the IoT Agent. HTTP uses a request/response paradigm where each device connects directly to the IoT Agent.\nMQTT is different in that publish-subscribe is event-driven and pushes messages to clients. It requires an additional\ncentral communication point (known as the MQTT broker) which it is in charge of dispatching all messages between the senders and the rightful receivers. Each client that publishes a message to the broker, includes a <strong>topic</strong> into the message. The <strong>topic</strong> is the routing information for the broker. Each client that wants to receive messages subscribes to a certain <strong>topic</strong> and the broker delivers all messages with the matching <strong>topic</strong> to the client. Therefore the clients don’t have to know each other, they only communicate over the <strong>topic</strong>. This architecture enables highly scalable solutions without dependencies between the data producers and the data consumers.</p>\n<p>The UltraLight 2.0 IoT Agent will only send or interpret messages using the <a href=\"http://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual\">UltraLight 2.0</a> syntax,\nhowever it can be used to send and receive messages over multiple <strong>transport</strong> mechanisms. Therefore we\nare able to use the same FIWARE generic enabler to connect to a wider range of IoT devices.</p>\n<h4 id=\"mosquitto-mqtt-broker\">Mosquitto MQTT Broker</h4>\n<p><a href=\"https://mosquitto.org/\">Mosquitto</a> is a readily available, open source MQTT broker which will be used during this tutorial.\nIt is available licensed under EPL/EDL. More information can be found at <a href=\"https://mosquitto.org/\">https://mosquitto.org/</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. Details of the architecture and protocol used can be found in the <a href=\"https://github.com/Fiware/tutorials.IoT-Sensors\">IoT Sensors tutorial</a>\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-over-MQTT/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.IoT-Agent/\">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-Agent/\">previous tutorial</a> \nAdditionally will add an instance of the <a href=\"https://mosquitto.org/\">Mosquitto</a> MQTT broker which is open source and available under the EPL/EDL.</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:</li>\n</ul>\n<ul>\n<li>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> MQTT topics for the MQTT Broker</li>\n<li>listen to the <strong>MQTT Broker</strong> on registered topics to send measurements northbound</li>\n</ul>\n<ul>\n<li>The <a href=\"https://mosquitto.org/\">Mosquitto</a> <strong>MQTT Broker</strong> which acts as a central communication point, passing \nMQTT topics between the <strong>IoT Agent</strong> and IoT devices as necessary.</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>A webserver acting as set of <a href=\"https://github.com/Fiware/tutorials.IoT-Sensors\">dummy IoT devices</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 MQTT.</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 proprietary 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</ul>\n<p>Since all interactions between the elements are initiated by HTTP or MQTT requests over TCP, the entities can be containerized and run from exposed ports. </p>\n<p><img src=\"https://fiware.github.io/tutorials.IoT-over-MQTT/img/architecture.png\" alt=\"\"></p>\n<p>The necessary configuration information for wiring up the Mosquitto MQTT Broker, 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=\"mosquitto-configuration\">Mosquitto Configuration</h2>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-yaml\">  mosquitto:\n    image: eclipse-mosquitto\n    hostname: mosquitto\n    container_name: mosquitto\n    networks:\n        - default\n    expose:\n        - \"1883\"\n        - \"9001\"\n    ports:\n        - \"1883:1883\"\n        - \"9001:9001\"\n    volumes:\n      - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf\n    \n</code></pre>\n<p>The <code>mosquitto</code> container is listening on two ports: </p>\n<ul>\n<li>Port <code>3000</code> is exposed so we can post MQTT topics</li>\n<li>Port <code>9001</code> is the standard port for HTTP/Websocket communications</li>\n</ul>\n<p>The attached volume is a <a href=\"https://github.com/Fiware/tutorials.IoT-over-MQTT/blob/master/osquitto/mosquitto.conf\">configuration file</a> used to increase the debug level of the MQTT Message Broker.</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        - \"DUMMY_DEVICES_PORT=3001\"\n        - \"DUMMY_DEVICES_API_KEY=4jggokgpepnvsb2uv4s40d59ov\"\n        - \"DUMMY_DEVICES_TRANSPORT=MQTT\"\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>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 official 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: fiware-iot-agent\n    depends_on:\n      - mongo-db\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=mongo-db\"\n        - \"IOTA_MONGO_PORT=27017\"\n        - \"IOTA_MONGO_DB=iotagentul\"\n        - \"IOTA_PROVIDER_URL=http://iot-agent:4041\"\n        - \"IOTA_MQTT_HOST=mosquitto\"\n        - \"IOTA_MQTT_PORT=1883\"\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_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<tr>\n<td>IOTA_MQTT_HOST</td>\n<td><code>mosquitto</code></td>\n<td>The host name of the MQTT Broker</td>\n</tr>\n<tr>\n<td>IOTA_MQTT_PORT</td>\n<td><code>1883</code></td>\n<td>The port the MQTT Broker is listening on to receive topics</td>\n</tr>\n</tbody>\n</table>\n</div><p>As you can see, use of the MQTT transport is driven by only two environment variables <code>IOTA_MQTT_HOST</code> and <code>IOTA_MQTT_PORT</code></p>\n<h1 id=\"prerequisites\">Prerequisites</h1>\n<h2 id=\"docker-and-docker-compose\">Docker and Docker Compose</h2>\n<p>To keep things simple all components will be run using <a href=\"https://www.docker.com\">Docker</a>. <strong>Docker</strong> is a container technology which allows to different components isolated into their respective environments. </p>\n<ul>\n<li>To install Docker on Windows follow the instructions <a href=\"https://docs.docker.com/docker-for-windows/\">here</a></li>\n<li>To install Docker on Mac follow the instructions <a href=\"https://docs.docker.com/docker-for-mac/\">here</a></li>\n<li>To install Docker on Linux follow the instructions <a href=\"https://docs.docker.com/install/\">here</a></li>\n</ul>\n<p><strong>Docker Compose</strong> is a tool for defining and running multi-container Docker applications. A \n<a href=\"https://raw.githubusercontent.com/Fiware/tutorials.IoT-over-MQTT/master/docker-compose.yml\">YAML file</a> is used\nconfigure the required services for the application. This means all container services can be brought up in a single \ncommand. Docker Compose is installed by default  as part of Docker for Windows and  Docker for Mac, however Linux users \nwill need to follow the instructions found  <a href=\"https://docs.docker.com/compose/install/\">here</a></p>\n<h2 id=\"cygwin-for-windows\">Cygwin for Windows</h2>\n<p>We will start up our services using a simple Bash script. Windows users should download <a href=\"http://www.cygwin.com/\">cygwin</a> to provide a command line functionality similar to a Linux distribution on Windows.</p>\n<h1 id=\"start-up\">Start Up</h1>\n<p>Before you start you should ensure that you have obtained or built the necessary Docker images locally. Please clone the repository and create the necessary images by running the commands as shown:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">git clone git@github.com:Fiware/tutorials.IoT-over-MQTT.git\ncd tutorials.IoT-over-MQTT\n\n./services create\n</code></pre>\n<blockquote>\n<p><strong>Note</strong> The <code>context-provider</code> image has not yet been pushed to Docker hub.\nFailing to build the Docker sources before proceeding will result in the following error:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code>Pulling context-provider (fiware/cp-web-app:latest)...\nERROR: The image for the service you're trying to recreate has been removed.\n</code></pre></blockquote>\n<p>Thereafter, all services can be initialized from the command line by running the <a href=\"https://github.com/Fiware/tutorials.IoT-over-MQTT/blob/master/services\">services</a> Bash script provided within the repository:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">./services start\n</code></pre>\n<blockquote>\n<p>:information_source: <strong>Note:</strong> If you want to clean up and start over again you can do so with the following command:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">./services stop\n</code></pre>\n</blockquote>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[{"content":"What is MQTT?","slug":"what-is-mqtt"},{"content":"Architecture","slug":"architecture"},{"content":"Prerequisites","slug":"prerequisites"},{"content":"Start Up","slug":"start-up"}],"owner":"513743","collectionId":"fddcfd01-0c04-4da3-bc34-2ad6ff9fbf0e","publishedId":"RWEiKxtp","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"45D3DD"},"publishDate":"2020-01-02T11:03:30.000Z"},"item":[{"name":"Checking Mosquitto Health","item":[],"id":"f051f52b-2e72-46e3-8f0f-161e1bf98df6","description":"<p>We will start by mimicking the roles of both the IoT Agent and a dummy IoT device and send and receive some messages\nusing MQTT. This section of the tutorial requires several open terminals.</p>\n<h3 id=\"start-an-mqtt-subscriber-1st-terminal\">Start an MQTT Subscriber (1st Terminal)</h3>\n<p>Eventually once we have wired by the system correctly, IoT Agent will subscribe to all relevent events to listen for\nnorthbound traffic in the form of sensor measurements. It therefore will need to make a subscription\nacross all topics. Similarly an accuator must subscribe to a single topic to receive events which effect itself when \ncommands are sent southbound. To check that the lines of communication are open, we can subscribe to a given topic,\nand see that we are able to receive something when a message is published.</p>\n<p>Open a <strong>new terminal</strong>, and create a new running <code>mqtt-subscriber</code> Docker container as follows:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">docker run -it --rm --name mqtt-subscriber \\\n  --network fiware_default efrecon/mqtt-client sub -h mosquitto -t \"#\"\n</code></pre>\n<p>The terminal will then be ready to receive events</p>\n<h3 id=\"start-an-mqtt-publisher-2nd-terminal\">Start an MQTT Publisher (2nd Terminal)</h3>\n<p>A sensor sending northbound measurements will publish to those measurements to the MQTT Broker to be passed on to \nany subscriber than  wants them. The sensor will not need to make a connection to the subscriber directly. </p>\n<p>Open a <strong>new terminal</strong>, and run a  <code>mqtt-publisher</code> Docker container to send a message as follows:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">docker run -it --rm -name mqtt-publisher \\\n  --network fiware_default efrecon/mqtt-client pub -h mosquitto -m \"HELLO WORLD\" -t \"test\"\n</code></pre>\n<h4 id=\"1st-terminal---result\">1st terminal - Result:</h4>\n<p>If the MQTT Broker is functioning correctly, the message should be received in the other terminal</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code>HELLO WORLD\n</code></pre><h3 id=\"stop-an-mqtt-subscriber-1st-terminal\">Stop an MQTT Subscriber (1st Terminal)</h3>\n<p>To terminate the MQTT subscriber, run the following Docker command:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">docker stop mqtt-subscriber\n</code></pre>\n<h3 id=\"show-mosquitto-log\">Show Mosquitto Log</h3>\n<p>To show that the communication occurred via the <strong>MQTT Broker</strong>, we can inspect the log of the <code>mosquitto</code> Docker container as shown:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">docker logs --tail 10 mosquitto\n</code></pre>\n<h4 id=\"result\">Result:</h4>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code>1529661883: New client connected from 172.18.0.5 as mqttjs_8761e518 (c1, k0).\n1529662472: New connection from 172.18.0.7 on port 1883.\n1529662472: New client connected from 172.18.0.7 as mosqpub|1-5637527c63c1 (c1, k60).\n1529662472: Client mosqpub|1-5637527c63c1 disconnected.\n1529662614: New connection from 172.18.0.7 on port 1883.\n1529662614: New client connected from 172.18.0.7 as mosqsub|1-64b27d675f58 (c1, k60).\n1529662623: New connection from 172.18.0.8 on port 1883.\n1529662623: New client connected from 172.18.0.8 as mosqpub|1-ef03e74b0270 (c1, k60).\n1529662623: Client mosqpub|1-ef03e74b0270 disconnected.\n1529667841: Socket error on client mosqsub|1-64b27d675f58, disconnecting.\n</code></pre>","event":[{"listen":"prerequest","script":{"id":"c6502f9d-8906-46d9-bb87-c141718201de","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"f7419bd0-dfb9-4fd4-8b5e-d8543b7e92fc","type":"text/javascript","exec":[""]}}],"_postman_id":"f051f52b-2e72-46e3-8f0f-161e1bf98df6"},{"name":"Connecting IoT Devices","item":[{"name":"IoT Agent - Obtain Version Information","id":"8d6628ba-66ee-433f-93da-844477a096a3","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":"8d6628ba-66ee-433f-93da-844477a096a3"},{"name":"IoT Agent - Create a Service Group","id":"7d232a2d-6522-4230-9a18-bd35ee197c1e","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\":    \"\"\n   }\n ]\n}"},"url":"http://localhost:4041/iot/services","description":"<p>Invoking group provision is always the the first step in connecting devices. For MQTT communication, provisioning supplies the authentication key so the IoT Agent will know which <strong>topic</strong> it must\nsubscribe to.</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 communicating by sending messages to the <code>/4jggokgpepnvsb2uv4s40d59ov</code> <strong>topic</strong></p>\n<p>The <code>resource</code> attribute is left blank since HTTP communication is not being used.</p>\n<p>The URL location of  <code>cbroker</code> is an optional attribute - if it is not provided, the IoT\nAgent uses the default context broker URL as defined in the configuration file, however\nit has been added here for completeness.</p>\n","urlObject":{"protocol":"http","path":["iot","services"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"7d232a2d-6522-4230-9a18-bd35ee197c1e"},{"name":"IoT Agent - Provision a Sensor","id":"6f10865d-9726-4625-bf4b-c5fab9f6a229","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     \"protocol\":    \"PDI-IoTA-UltraLight\",\n     \"transport\":   \"MQTT\",\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}\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":"6f10865d-9726-4625-bf4b-c5fab9f6a229"},{"name":"Context Broker - Read the Motion Sensor","id":"8ab4308c-d71a-42e7-b0b9-183f4c3bf3d7","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>To make a dummy measurement, send a topic to the <strong>MQTT Broker</strong> as shown.</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code>docker run -it --rm --name mqtt-publisher --network \\\n  fiware_default efrecon/mqtt-client pub -h mosquitto -m \"c|1\" -t \"/4jggokgpepnvsb2uv4s40d59ov/motion001/attrs\"\n</code></pre><p>Then make the context data request.</p>\n<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.</p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Motion:001"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"8ab4308c-d71a-42e7-b0b9-183f4c3bf3d7"},{"name":"IoT Agent - Provision an Actuator","id":"b7e72fc1-566d-416b-9c7a-9060b93c90bb","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      \"protocol\": \"PDI-IoTA-UltraLight\",\n      \"apikey\":      \"4jggokgpepnvsb2uv4s40d59ov\",\n      \"transport\": \"MQTT\",\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. The <code>transport</code> attribute defines the communications\nprotocol to be used. For MQTT communications, the <code>endpoint</code> attribute  is not required as there is no HTTP url \nwhere the device is listening for commands.  The array of commands\nis mapped to directly to messages sent to the  <code>/&lt;api-key&gt;/&lt;device-id&gt;/cmd</code> <strong>topic</strong> \nThe <code>commands</code> array includes a list of each command that can be invoked. </p>\n<p>The example below provisions a bell with the <code>deviceId=bell001</code>.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"b7e72fc1-566d-416b-9c7a-9060b93c90bb"},{"name":"IoT Agent - Invoke a Command","id":"4d8759c8-636a-4af6-a7c4-3af980e812eb","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 sent from the IoT Agent to a\ndevice by making a REST request directly 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":"4d8759c8-636a-4af6-a7c4-3af980e812eb"},{"name":"Context Broker - Read the Command Result","id":"a9cc1f08-d4de-45cf-9640-e0fbb2519003","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":"a9cc1f08-d4de-45cf-9640-e0fbb2519003"},{"name":"IoT Agent - Provision a Smart Door","id":"6bc054c7-490c-434a-bd79-fbcfcc558349","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      \"protocol\": \"PDI-IoTA-UltraLight\",\n      \"transport\": \"MQTT\",\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 \nmaking an HTTP POST request with both <code>attributes</code> and <code>command</code> attributes in the body of the \nrequest. Once again the <code>transport=MQTT</code> attribute defines the communications protocol to be used, \nand no <code>endpoint</code> attribute is required as there is no HTTP url where the device is listening \nfor commands.</p>\n","urlObject":{"protocol":"http","path":["iot","devices"],"host":["localhost:4041"],"query":[],"variable":[]}},"response":[],"_postman_id":"6bc054c7-490c-434a-bd79-fbcfcc558349"},{"name":"IoT Agent - Provision a Smart Lamp","id":"1cab1509-8f73-48b5-bf7c-03ef5c79be4b","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      \"protocol\": \"PDI-IoTA-UltraLight\",\n      \"transport\": \"MQTT\",\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":"1cab1509-8f73-48b5-bf7c-03ef5c79be4b"},{"name":"IoT Agent - List all Provisioned Devices","id":"de6d15a4-f295-45c1-8299-0fe6bb3e1329","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":"de6d15a4-f295-45c1-8299-0fe6bb3e1329"}],"id":"d48dcdbb-92a8-4f1b-aa7a-2f7b71817417","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":"d48dcdbb-92a8-4f1b-aa7a-2f7b71817417"},{"name":"Enabling Context Broker Commands","item":[{"name":"Bell Commands","item":[{"name":"Register Bell Commands","id":"69240a49-f0e6-47f0-89d4-8c2f650a6f02","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"},{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":"{\n  \"description\": \"Bell Commands\",\n  \"dataProvided\": {\n    \"entities\": [\n      {\n        \"id\": \"urn:ngsi-ld:Bell:001\", \"type\": \"Bell\"\n      }\n    ],\n    \"attrs\": [\"ring\"]\n  },\n  \"provider\": {\n    \"http\": {\"url\": \"http://orion:1026/v1\"},\n    \"legacyForwarding\": true\n  }\n}"},"url":"http://localhost:1026/v2/registrations?","description":"<p>This example registers the <code>ring</code> command for the entity with the <code>id=\"urn:ngsi-ld:Bell:001\"</code></p>\n<p>To register the command we need to inform Orion that the URL <code>http://orion:1026/v1</code> is able to provide\nthe missing <code>ring</code> attribute. This will then be forwarded on to the IoT Agent. As you see this is an NGSI v1 \nendpoint and therefore the <code>legacyForwarding</code> attribute must also be set.</p>\n","urlObject":{"protocol":"http","path":["v2","registrations"],"host":["localhost:1026"],"query":[{"disabled":true,"description":{"content":"<p>Entity type, to avoid ambiguity in case there are several entities with the same entity id</p>\n","type":"text/plain"},"key":"type","value":"Store"},{"disabled":true,"description":{"content":"<p>Ordered list of attribute names to display</p>\n","type":"text/plain"},"key":"attrs","value":"name"}],"variable":[]}},"response":[],"_postman_id":"69240a49-f0e6-47f0-89d4-8c2f650a6f02"},{"name":"Ring Bell","id":"eeb5e73d-15fe-47d3-9369-da47ff875fe9","request":{"method":"PATCH","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"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/attrs","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":[],"variable":[]}},"response":[],"_postman_id":"eeb5e73d-15fe-47d3-9369-da47ff875fe9"},{"name":"Bell Status","id":"4dc4553c-6fcc-4310-a8f9-6efcd60af796","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":"4dc4553c-6fcc-4310-a8f9-6efcd60af796"}],"id":"9474ae5c-90c5-4bc0-9acd-38255fd9b614","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":"9474ae5c-90c5-4bc0-9acd-38255fd9b614"},{"name":"Smart Door Commands","item":[{"name":"Register Smart Door Commands","id":"d4b0b1be-4fa6-4a1b-a460-3ab875105849","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"},{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":"{\n  \"description\": \"Door Commands\",\n  \"dataProvided\": {\n    \"entities\": [\n      {\n        \"id\": \"urn:ngsi-ld:Door:001\", \"type\": \"Door\"\n      }\n    ],\n    \"attrs\": [ \"lock\", \"unlock\", \"open\", \"close\"]\n  },\n  \"provider\": {\n    \"http\": {\"url\": \"http://orion:1026/v1\"},\n    \"legacyForwarding\": true\n  }\n}"},"url":"http://localhost:1026/v2/registrations?","description":"<p>This example registers the <code>lock</code>, <code>unlock</code>, <code>open</code> and <code>close</code> commands for the entity with\nthe <code>id=\"urn:ngsi-ld:Door:001\"</code></p>\n<p>To register the commands we need to inform Orion that the URL <code>http://orion:1026/v1</code> is able to provide\nthe missing  attributes. This will then be forwarded on to the IoT Agent. As you see this is an NGSI v1 \nendpoint and therefore the <code>legacyForwarding</code> attribute must also be set.</p>\n","urlObject":{"protocol":"http","path":["v2","registrations"],"host":["localhost:1026"],"query":[{"disabled":true,"description":{"content":"<p>Entity type, to avoid ambiguity in case there are several entities with the same entity id</p>\n","type":"text/plain"},"key":"type","value":"Store"},{"disabled":true,"description":{"content":"<p>Ordered list of attribute names to display</p>\n","type":"text/plain"},"key":"attrs","value":"name"}],"variable":[]}},"response":[],"_postman_id":"d4b0b1be-4fa6-4a1b-a460-3ab875105849"},{"name":"Open a Door","id":"62dd2cf7-f7e6-4b14-b760-a7e81f0da36a","request":{"method":"PATCH","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n\t\"open\": {\n    \t\"type\" : \"command\",\n    \t\"value\" : \"\"\n\t}\n}"},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001/attrs","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":[],"variable":[]}},"response":[],"_postman_id":"62dd2cf7-f7e6-4b14-b760-a7e81f0da36a"},{"name":"Door Status","id":"1585b935-484b-424a-b6f6-1c4eb16bac9c","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":"1585b935-484b-424a-b6f6-1c4eb16bac9c"}],"id":"a8b64c11-64c7-4c87-9bea-03fc6763992b","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":"a8b64c11-64c7-4c87-9bea-03fc6763992b"},{"name":"Smart Lamp","item":[{"name":"Register Smart Lamp Commands","id":"04a8ed23-b4ef-4559-9970-f779e32b91c2","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"},{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"}],"body":{"mode":"raw","raw":"{\n  \"description\": \"Lamp Commands\",\n  \"dataProvided\": {\n    \"entities\": [\n      {\n        \"id\": \"urn:ngsi-ld:Lamp:001\",\"type\": \"Lamp\"\n      }\n    ],\n    \"attrs\": [ \"on\", \"off\" ]\n  },\n  \"provider\": {\n    \"http\": {\"url\": \"http://orion:1026/v1\"},\n    \"legacyForwarding\": true\n  }\n}"},"url":"http://localhost:1026/v2/registrations?","description":"<p>This example registers the <code>on</code> and <code>off</code> commands for the entity with\nthe <code>id=\"urn:ngsi-ld:Lamp:001\"</code></p>\n<p>To register the commands we need to inform Orion that the URL <code>http://orion:1026/v1</code> is able to provide\nthe missing  attributes. This will then be forwarded on to the IoT Agent. As you see this is an NGSI v1 \nendpoint and therefore the <code>legacyForwarding</code> attribute must also be set.</p>\n","urlObject":{"protocol":"http","path":["v2","registrations"],"host":["localhost:1026"],"query":[{"disabled":true,"description":{"content":"<p>Entity type, to avoid ambiguity in case there are several entities with the same entity id</p>\n","type":"text/plain"},"key":"type","value":"Store"},{"disabled":true,"description":{"content":"<p>Ordered list of attribute names to display</p>\n","type":"text/plain"},"key":"attrs","value":"name"}],"variable":[]}},"response":[],"_postman_id":"04a8ed23-b4ef-4559-9970-f779e32b91c2"},{"name":"Switch On a Lamp","id":"2ab37c1d-b8f3-4dd4-8057-a06f1241d079","request":{"method":"PATCH","header":[{"key":"fiware-service","value":"openiot"},{"key":"fiware-servicepath","value":"/"},{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n\t\"on\": {\n    \t\"type\" : \"command\",\n    \t\"value\" : \"\"\n\t}\n}"},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs","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":[],"variable":[]}},"response":[],"_postman_id":"2ab37c1d-b8f3-4dd4-8057-a06f1241d079"},{"name":"Lamp Status","id":"2972854d-3613-432e-a09f-b58de25fc061","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":"2972854d-3613-432e-a09f-b58de25fc061"}],"id":"32bdc33f-3795-48d0-8fa1-edb0d988a34d","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":"32bdc33f-3795-48d0-8fa1-edb0d988a34d"},{"name":"List Provisioned Devices","id":"adfc1b0b-1257-4721-a243-432377bc7eb3","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":"adfc1b0b-1257-4721-a243-432377bc7eb3"}],"id":"10053cd1-528f-4891-baa2-c1bb09ca245d","description":"<p>Having connected up the IoT Agent to the IoT devices, we now need to inform the Orion Context Broker that the commands\nare available. In other words we need to register the IoT Agent as a <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":"10053cd1-528f-4891-baa2-c1bb09ca245d"}],"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"}]}