{"_id":"@anersonluisribeiro/iotagent-nodejs","_rev":"2-1ba2c5dce88787cbbaa8faac78c6f4d7","name":"@anersonluisribeiro/iotagent-nodejs","dist-tags":{"latest":"2.1.0-beta.9"},"versions":{"2.1.0-beta.8":{"name":"@anersonluisribeiro/iotagent-nodejs","version":"2.1.0-beta.8","description":"Base iotagent functionality for dojot","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/dojot/iotagent-nodejs.git"},"keywords":["dojot","iot"],"author":{"name":"Matheus Magalhaes"},"bugs":{"url":"https://github.com/dojot/iotagent-nodejs/issues"},"homepage":"https://github.com/dojot/iotagent-nodejs/#readme","license":"GPL-3.0","dependencies":{"@dojot/dojot-module":"0.0.1-beta.8","@dojot/dojot-module-logger":"0.0.1-alpha.5","axios":"^0.17.1","js-base64":"^2.3.2","uuid":"^3.2.1"},"gitHead":"cfbd8039adcfd7d5fed587d261dd01bc157e7626","_id":"@anersonluisribeiro/iotagent-nodejs@2.1.0-beta.8","_npmVersion":"6.5.0","_nodeVersion":"11.9.0","_npmUser":{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"},"dist":{"integrity":"sha512-eNOnHxuIDyfkTi/bgDk9EoMU+7OYwmbmrCQ1r1y8Zqa3BYn30QR0YuHML/0j3PQE1uEAPUkvganf8d9hj8BIvg==","shasum":"6a0cc04cedf4c5675d73730b3f53a3f1e2754569","tarball":"https://registry.npmjs.org/@anersonluisribeiro/iotagent-nodejs/-/iotagent-nodejs-2.1.0-beta.8.tgz","fileCount":11,"unpackedSize":52409,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeovk4CRA9TVsSAnZWagAAvkkQAJVAk3EJDqvcxdANV/NO\nP8h1S71U6X+kyV6TbuBzXZgyv6FDZ07qtqq317jxp0rn0VWYlTOzgAP473s8\nMRL7KIViE9osiajgyF1GTruUksmXVQRwjb/EBYcWCevdYykxo2L8iYTKl0zK\nAFtq01aUb7pKGs2oKGzRwjDg9CLu3iXW+h+1vhCWrxMv44iCVbkeqshCEYXM\nshgqZ7sup4uqs6X4cDhTE4InxwUpDq09pxwtaMxJsnufi+XrFGPySTTgXhBh\niMA9HOd6ut09YcEIl6oDx1S6xB1R8OXeOnSTCmwfhkyY5cjNfSwNL6Lb6DS/\nq58v6OEvVVDjxCypZHOviPTVOV9qKniV7ZxhbzR8DGS43c0lyrPho1gcm8j9\nU1Okf4WimU0edmhbb5708fjCxbfbUfj+JAEndHRJkvUl5mN0DgKLsLyrbRrL\ngJdEZ3oNzRmNmvZah+sQaHwUsgzHf7qwHYH7GTwuPQt8jn0dR3lDGUZ0rHLi\nTEpmZAzIU1n778bZP6tNUfPof8nXIgzjcuZ/kViXo9oensX9InBt00fM71+i\niIfyk27E9M80dG0fKyti00UFAWJSAeIIXGAkaiIaPiJmuZg+WJEkxtX5ia2P\nKftUm0NwZnKY2FqNTRQvyg7kORf8yjlBEVRJnNCpo08qowqS1FBE2usaxEBo\nNugH\r\n=5MY4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBoSuhSHBNNVmXLnsZFuPqeApBCL+FlQbW6/UwfIGB1VAiEA9qkxegZbei6LY1eSvxmKLrTfzfEyNCWMARWqkheO61M="}]},"maintainers":[{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/iotagent-nodejs_2.1.0-beta.8_1587738935496_0.652781724962425"},"_hasShrinkwrap":false},"2.1.0-beta.9":{"name":"@anersonluisribeiro/iotagent-nodejs","version":"2.1.0-beta.9","description":"Base iotagent functionality for dojot","main":"lib/index.js","types":"lib/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/dojot/iotagent-nodejs.git"},"keywords":["dojot","iot"],"author":{"name":"Matheus Magalhaes"},"bugs":{"url":"https://github.com/dojot/iotagent-nodejs/issues"},"homepage":"https://github.com/dojot/iotagent-nodejs/#readme","license":"GPL-3.0","dependencies":{"@dojot/dojot-module":"0.0.1-beta.8","@dojot/dojot-module-logger":"0.0.1-alpha.5","axios":"^0.17.1","js-base64":"^2.3.2","uuid":"^3.2.1"},"gitHead":"cfbd8039adcfd7d5fed587d261dd01bc157e7626","_id":"@anersonluisribeiro/iotagent-nodejs@2.1.0-beta.9","_npmVersion":"6.5.0","_nodeVersion":"11.9.0","_npmUser":{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"},"dist":{"integrity":"sha512-peMe0HWaBZQsPoy1KYQERNu71S19yNZNJk2OdAJRu4rBpITlGBRyD8O9BVJje6ReAeUrKBRAhYiXCVzgYR0A0A==","shasum":"162659368c7b60302bc351d475b21c88881f2688","tarball":"https://registry.npmjs.org/@anersonluisribeiro/iotagent-nodejs/-/iotagent-nodejs-2.1.0-beta.9.tgz","fileCount":11,"unpackedSize":52420,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeovuGCRA9TVsSAnZWagAAMwYP/iDW1ahqRwNF+6USnD4a\na0VVrcnhkxvTpoJ6cDjY8CgvFnhk7Lq9JC+70SPlF9Iz1E+c4iFgJ2YOKQkI\nv1Q0B+4yOLQ5mZkL+VvGauQ4tt30rie1H9SsWV/zALbesgEBimk3p4P+VNdP\nM9DNffqCrfIIscKuLba6CUErevHJecoR+35bRsZJYwP+4cguckv21NikMGum\nOp+97SUePljt10IDbKPFzS5nVKjia3KkTX+WuuE+wmMxk5V4VgPOMfRSYknR\nZWoaKFs1Ft0mznLWgR1VB86bhWf9PKqOJAx2DKHlqvNSO3lMLuvEA/sYdI2M\njJC5Ho+ltEg53tTpT9whAwmp4T6hw5SxbtXXNn3L9yBmHtLfycsBIqdgIFJz\ngkBWEEjiyIm0buZYCVBEiUwJ5X6+Be7DcaYm5+rBxYYgbo6fpW0da7gkOYFk\nVnFHkVBR09HRAAabEURXNxTZIrHcjgJEbFvIGaMLhwa8MP7/DX84GU6EECzB\nduxELfPyNw6KtdsGy3tR19RlT8dkejrt74/bbWKKGivFxCHk5wN1kypvl4yc\n3dr0Yc+hgr/v3gd/ia7B/+yG/kj/fddLcoDGoM6f+heHwTCri/ZiFfAX18wZ\ne/0NOEchwLWJwlLsP1x3/2brQLY09ck8feh4PpExfOOpnjxAZqlHoH787wzs\nnylH\r\n=JiLi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBIyBcvoO3E1xtmDqot6v5uqvGWMqW6RvVN/9DQuRf6ZAiEAyjWrezDhBePVMVm9ncqfx6y1zKrIcd/5VhCXvoTlU/c="}]},"maintainers":[{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/iotagent-nodejs_2.1.0-beta.9_1587739525852_0.861561938995973"},"_hasShrinkwrap":false}},"time":{"created":"2020-04-24T14:35:35.446Z","2.1.0-beta.8":"2020-04-24T14:35:35.716Z","modified":"2022-04-04T14:05:11.026Z","2.1.0-beta.9":"2020-04-24T14:45:25.990Z"},"maintainers":[{"name":"anersonluisribeiro","email":"anderson_lr@hotmail.com"}],"description":"Base iotagent functionality for dojot","homepage":"https://github.com/dojot/iotagent-nodejs/#readme","keywords":["dojot","iot"],"repository":{"type":"git","url":"git+https://github.com/dojot/iotagent-nodejs.git"},"author":{"name":"Matheus Magalhaes"},"bugs":{"url":"https://github.com/dojot/iotagent-nodejs/issues"},"license":"GPL-3.0","readme":"# dojot IoT agent base library\n\nThis library contains all common operations that a IoT agent might need from\ndojot. This includes receiving notifications related to device operations, such\nas creation, deletion and updates, as well as methods for sending device\ndata to other components.\n\n## How to install\n\nJust execute\n\n```bash\nnpm install @dojot/iotagent-nodejs\n```\n\n## How to use\n\nThis library has one main function, which is `updateAttrs`. Furthermore, it\nalso generated events \"device.create\", \"device.remove\", \"device.update\",\nand \"device.configure\" in \"iotagent.device\" subject. The `updateAttrs` function\nand all events are shown in the folloing code.\n\n```javascript\nvar iotagentLib = require('@dojot/iotagent-nodejs');\nvar logger = require(\"@dojot/dojot-module-logger\").logger;\nvar util = require(\"util\");\n\nlogger.debug(\"Initializing IoT agent...\");\nvar iotagent = new iotagentLib.IoTAgent();\niotagent.init().then(() => {\n    logger.debug(\"... IoT agent was initialized\");\n\n    logger.debug(\"Registering callbacks for device events...\");\n    let deviceId = undefined;\n    iotagent.on('iotagent.device', 'device.create', (tenant, event) => {\n        logger.debug(`Got device creation message. Tenant is ${tenant}.`);\n        logger.debug(`Data is: ${util.inspect(event)}`);\n        logger.debug('Got configure event from Device Manager', event)\n        // This is just to get one valid device ID to be used in\n        // updateAttrs sample.\n        deviceId = event.data.id;\n    });\n\n    iotagent.on('iotagent.device', 'device.configure', (tenant, event) => {\n        logger.debug(`Got device actuation message. Tenant is ${tenant}.`);\n        logger.debug(`Data is: ${util.inspect(event)}`);\n        logger.debug('Got configure event from Device Manager', event)\n    });\n\n    iotagent.on('iotagent.device', 'device.remove', (tenant, event) => {\n        logger.debug(`Got device removal message. Tenant is ${tenant}.`);\n        logger.debug(`Data is: ${util.inspect(event)}`);\n        logger.debug('Got configure event from Device Manager', event)\n    });\n\n    iotagent.on('iotagent.device', 'device.update', (tenant, event) => {\n        logger.debug(`Got device update message. Tenant is ${tenant}.`);\n        logger.debug(`Data is: ${util.inspect(event)}`);\n        logger.debug('Got configure event from Device Manager')\n    });\n\n    logger.debug(\"... callbacks for device events were registered.\")\n\n    // If there is any configured device, the callback associated to \"device.create\"\n    // event will be called.\n    logger.debug(\"Requesting library to generate event for each device...\")\n    iotagent.messenger.generateDeviceCreateEventForActiveDevices();\n    logger.debug(\"... event generation was requested.\")\n\n    let i = 0;\n    const sendMessage = () => {\n      i++;\n      let msg = {\n          \"attr1\": `this is a sample reading: ${i}`,\n      };\n      let metadata = {\n\n      };\n      if (deviceId != undefined) {\n        iotagent.updateAttrs(deviceId, \"admin\", msg, metadata);\n      }\n      setTimeout(() => {\n        sendMessage();\n      }, 2000);\n    };\n\n    sendMessage();\n});\n```\n\nDevice events have the following format:\n\n- device.create:\n\n```json\n{\n  \"event\": \"create\",\n  \"meta\": {\n    \"service\": \"admin\"\n  },\n  \"data\": {\n    \"id\": \"efac\",\n    \"label\" : \"Device 1\",\n    \"templates\" : [ 1, 2, 3],\n    \"attrs\" : {\n\n    },\n    \"created\" : \"2018-02-06T10:43:40.890330+00:00\"\n  }\n}\n```\n\n- device.update:\n\n```json\n{\n  \"event\": \"update\",\n  \"meta\": {\n    \"service\": \"admin\"\n  },\n  \"data\": {\n    \"id\": \"efac\",\n    \"label\" : \"Device 1\",\n    \"templates\" : [ 1, 2, 3],\n    \"attrs\" : {\n\n    },\n    \"created\" : \"2018-02-06T10:43:40.890330+00:00\"\n  }\n}\n```\n\n- device.remove:\n\n```json\n{\n  \"event\": \"remove\",\n  \"meta\": {\n    \"service\": \"admin\"\n  },\n  \"data\": {\n    \"id\": \"efac\"\n  }\n}\n```\n\n- device.configure:\n\n```json\n{\n  \"event\": \"configure\",\n  \"meta\": {\n    \"service\": \"admin\"\n  },\n  \"data\" : {\n    \"id\" : \"efac\",\n    \"attrs\": {\n      \"reset\" : 1,\n      \"step-motor\" : \"+45\"\n    }\n  }\n}\n```\n\nIn order to execute this code, the following environment variables can be set:\n\n```bash\n# These are the default values\nexport KAFKA_HOSTS=\"kafka:9092\"\nexport KAFKA_GROUP_ID=\"iotagent\"\nexport DATA_BROKER_URL=\"http://data-broker\"\nexport AUTH_URL=\"http://auth:5000\"\nexport DEVICE_MANAGER_URL=\"http://device-manager:5000\"\n```\nIt is important to notice that KAFKA_GROUP_ID variable must be set to something\ndifferent, as this is used by Kafka to select which clients will receive messages\nfrom a particular topic. If not set, all services that uses the same ID will\nbe selected at random to receive messages, which is probably not what you want.\n","readmeFilename":"README.md"}