diff --git a/doc/architecture.md b/doc/architecture.md index 54e4c9953..cbc2b5620 100644 --- a/doc/architecture.md +++ b/doc/architecture.md @@ -32,7 +32,7 @@ basis preprovisioning the devices). Device measures can have three different beh The following sequence diagram shows the different NGSI interactions an IoT Agent makes with the Context Broker, explained in the following subsections (using the example of a OMA Lightweight M2M device). -![General ](./img/ngsiInteractions.png 'NGSI Interactions') +![General ](./img/ngsiInteractions.png "NGSI Interactions") Be aware that the IoT Agents are only required to support NGSI10 operations `updateContext` and `queryContext` in their standard formats (currently in JSON format; XML deprecated) but will not answer to NGSI9 operations (or NGSI convenience @@ -254,7 +254,7 @@ the concrete IoT Agent implementations will be to map between the native device The following figure offers a graphical example of how a COAP IoT Agent work, ordered from the registration of the device to a command update to the device. -![General ](./img/iotAgentLib.png 'Architecture Overview') +![General ](./img/iotAgentLib.png "Architecture Overview") ### The `TimeInstant` element diff --git a/doc/caching-strategy.md b/doc/caching-strategy.md index 44cb59adb..112248aac 100644 --- a/doc/caching-strategy.md +++ b/doc/caching-strategy.md @@ -23,7 +23,6 @@ received from the database this allows multiple IoT Agent instances to access th This is the default operation mode with Mongo-DB. Whenever a measure is received, provisioning data is requested from the database. This may become a bottleneck in high availability systems. - ### MongoDB with in-memory Cache if `memCache.enabled = true` within the config this provides a transient memory-based cache in front of the mongo-DB @@ -45,5 +44,5 @@ IoT Agents would potential hold inconsistent provisioning data until the cache h ## Bypassing cache In some cases consistent provisioning data is more vital than throughput. When creating or updating a provisioned device -or service group adding a `cache` attribute with the value `true` will ensure that the data can be cached, otherwise it is never placed into a -cache and therefore always consistently received from the Mongo-DB instance. +or service group adding a `cache` attribute with the value `true` will ensure that the data can be cached, otherwise it +is never placed into a cache and therefore always consistently received from the Mongo-DB instance. diff --git a/doc/getting-started.md b/doc/getting-started.md index 20fe615be..692073f72 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -10,22 +10,22 @@ custom settings may also be required dependent upon the actual IoT Agent used. ```javascript config = { - logLevel: 'DEBUG', + logLevel: "DEBUG", contextBroker: { - host: 'orion', - port: '1026' + host: "orion", + port: "1026", }, server: { port: 4041, - host: '0.0.0.0' + host: "0.0.0.0", }, deviceRegistry: { - type: 'memory' + type: "memory", }, - service: 'openiot', - subservice: '/', - providerUrl: 'http://iot-agent:4041', - defaultType: 'Thing' + service: "openiot", + subservice: "/", + providerUrl: "http://iot-agent:4041", + defaultType: "Thing", }; ``` diff --git a/doc/howto.md b/doc/howto.md index 25e345f0e..2662a0a37 100644 --- a/doc/howto.md +++ b/doc/howto.md @@ -75,12 +75,12 @@ folder of your project. Remember to change the Context Broker IP to your local C Now we can begin with the code of our IoT Agent. The very minimum code we need to start an IoT Agent is the following: ```javascript -var iotAgentLib = require('iotagent-node-lib'), - config = require('./config'); +var iotAgentLib = require("iotagent-node-lib"), + config = require("./config"); iotAgentLib.activate(config, function (error) { if (error) { - console.log('There was an error activating the IOTA'); + console.log("There was an error activating the IOTA"); process.exit(1); } }); @@ -112,10 +112,10 @@ In order to add the Express dependency to your project, add the following line t The require section would end up like this (the standard `http` module is also needed): ```javascript -var iotAgentLib = require('iotagent-node-lib'), - http = require('http'), - express = require('express'), - config = require('./config'); +var iotAgentLib = require("iotagent-node-lib"), + http = require("http"), + express = require("express"), + config = require("./config"); ``` And install the dependencies as usual with `npm install`. You will have to require both `express` and `http` in your @@ -129,16 +129,16 @@ function initSouthbound(callback) { southboundServer = { server: null, app: express(), - router: express.Router() + router: express.Router(), }; - southboundServer.app.set('port', 8080); - southboundServer.app.set('host', '0.0.0.0'); + southboundServer.app.set("port", 8080); + southboundServer.app.set("host", "0.0.0.0"); - southboundServer.router.get('/iot/d', manageULRequest); + southboundServer.router.get("/iot/d", manageULRequest); southboundServer.server = http.createServer(southboundServer.app); - southboundServer.app.use('/', southboundServer.router); - southboundServer.server.listen(southboundServer.app.get('port'), southboundServer.app.get('host'), callback); + southboundServer.app.use("/", southboundServer.router); + southboundServer.server.listen(southboundServer.app.get("port"), southboundServer.app.get("host"), callback); } ``` @@ -154,18 +154,18 @@ function manageULRequest(req, res, next) { iotAgentLib.retrieveDevice(req.query.i, req.query.k, function (error, device) { if (error) { res.status(404).send({ - message: "Couldn't find the device: " + JSON.stringify(error) + message: "Couldn't find the device: " + JSON.stringify(error), }); } else { values = parseUl(req.query.d, device); - iotAgentLib.update(device.name, device.type, '', values, device, function (error) { + iotAgentLib.update(device.name, device.type, "", values, device, function (error) { if (error) { res.status(500).send({ - message: 'Error updating the device' + message: "Error updating the device", }); } else { res.status(200).send({ - message: 'Device successfully updated' + message: "Device successfully updated", }); } }); @@ -190,17 +190,17 @@ function parseUl(data, device) { } function createAttribute(element) { - var pair = element.split('|'), + var pair = element.split("|"), attribute = { name: pair[0], value: pair[1], - type: findType(pair[0]) + type: findType(pair[0]), }; return attribute; } - return data.split(',').map(createAttribute); + return data.split(",").map(createAttribute); } ``` @@ -227,14 +227,14 @@ show the modifications in the `activate()` function: ```javascript iotAgentLib.activate(config, function (error) { if (error) { - console.log('There was an error activating the IOTA'); + console.log("There was an error activating the IOTA"); process.exit(1); } else { initSouthbound(function (error) { if (error) { - console.log('Could not initialize South bound API due to the following error: %s', error); + console.log("Could not initialize South bound API due to the following error: %s", error); } else { - console.log('Both APIs started successfully'); + console.log("Both APIs started successfully"); } }); } @@ -286,7 +286,7 @@ A HTTP request library will be needed in order to make those calls. To this exte used. In order to do so, add the following require statement to the initialization code: ```javascript -request = require('request'); +request = require("request"); ``` and add the `request` dependency to the `package.json` file: @@ -303,11 +303,11 @@ and add the `request` dependency to the `package.json` file: The require section should now look like this: ```javascript -var iotAgentLib = require('iotagent-node-lib'), - http = require('http'), - express = require('express'), - request = require('request'), - config = require('./config'); +var iotAgentLib = require("iotagent-node-lib"), + http = require("http"), + express = require("express"), + request = require("request"), + config = require("./config"); ``` ### Implementation @@ -321,11 +321,11 @@ for the context provisioning requests. At this point, we should provide two hand ```javascript function queryContextHandler(id, type, service, subservice, attributes, callback) { var options = { - url: 'http://127.0.0.1:9999/iot/d', - method: 'GET', + url: "http://127.0.0.1:9999/iot/d", + method: "GET", qs: { - q: attributes.join() - } + q: attributes.join(), + }, }; request(options, function (error, response, body) { @@ -350,21 +350,21 @@ attributes). Here is the code for the `createResponse()` function: ```javascript function createResponse(id, type, attributes, body) { - var values = body.split(','), + var values = body.split(","), responses = []; for (var i = 0; i < attributes.length; i++) { responses.push({ name: attributes[i], - type: 'string', - value: values[i] + type: "string", + value: values[i], }); } return { id: id, type: type, - attributes: responses + attributes: responses, }; } ``` @@ -374,11 +374,11 @@ function createResponse(id, type, attributes, body) { ```javascript function updateContextHandler(id, type, service, subservice, attributes, callback) { var options = { - url: 'http://127.0.0.1:9999/iot/d', - method: 'GET', + url: "http://127.0.0.1:9999/iot/d", + method: "GET", qs: { - d: createQueryFromAttributes(attributes) - } + d: createQueryFromAttributes(attributes), + }, }; request(options, function (error, response, body) { @@ -388,7 +388,7 @@ function updateContextHandler(id, type, service, subservice, attributes, callbac callback(null, { id: id, type: type, - attributes: attributes + attributes: attributes, }); } }); @@ -406,13 +406,13 @@ representation of the attributes to the UL type expected by the device: ```javascript function createQueryFromAttributes(attributes) { - var query = ''; + var query = ""; for (var i in attributes) { - query += attributes[i].name + '|' + attributes[i].value; + query += attributes[i].name + "|" + attributes[i].value; if (i != attributes.length - 1) { - query += ','; + query += ","; } } @@ -555,9 +555,9 @@ variable and afterward the value of the multiCore in the `config.js` file. The r (the standard `http` module is also needed): ```javascript -var iotAgent = require('../lib/iotagent-implementation'), - iotAgentLib = require('iotagent-node-lib'), - config = require('./config'); +var iotAgent = require("../lib/iotagent-implementation"), + iotAgentLib = require("iotagent-node-lib"), + config = require("./config"); ``` It is important to mention the purpose of the `iotAgent` variable. It is the proper implementation of the IoT Agent @@ -573,9 +573,9 @@ about starting the IoTAgent: ```javascript iotAgentLib.startServer(config, iotAgent, function (error) { if (error) { - console.log(context, 'Error starting IoT Agent: [%s] Exiting process', error); + console.log(context, "Error starting IoT Agent: [%s] Exiting process", error); } else { - console.log(context, 'IoT Agent started'); + console.log(context, "IoT Agent started"); } }); ``` @@ -602,7 +602,7 @@ handlers themselves. Here we can see the definition of the configuration handler ```javascript function configurationHandler(configuration, callback) { - console.log('\n\n* REGISTERING A NEW CONFIGURATION:\n%s\n\n', JSON.stringify(configuration, null, 4)); + console.log("\n\n* REGISTERING A NEW CONFIGURATION:\n%s\n\n", JSON.stringify(configuration, null, 4)); callback(null, configuration); } ``` @@ -619,8 +619,8 @@ feature, let's use the provisioning handler to change the value of the type of t ```javascript function provisioningHandler(device, callback) { - console.log('\n\n* REGISTERING A NEW DEVICE:\n%s\n\n', JSON.stringify(device, null, 4)); - device.type = 'CertifiedType'; + console.log("\n\n* REGISTERING A NEW DEVICE:\n%s\n\n", JSON.stringify(device, null, 4)); + device.type = "CertifiedType"; callback(null, device); } ``` diff --git a/doc/installationguide.md b/doc/installationguide.md index c01aaf524..c1f758b83 100644 --- a/doc/installationguide.md +++ b/doc/installationguide.md @@ -160,7 +160,7 @@ used for the same purpose. For instance: ```javascript { - type: 'mongodb'; + type: "mongodb"; } ```