{"_id":"@andersonluisribeiro/iotagent-nodejs","_rev":"2-42e24030557e3634e902bce1086618fc","name":"@andersonluisribeiro/iotagent-nodejs","dist-tags":{"latest":"2.1.0-beta.10"},"versions":{"2.1.0-beta.9":{"name":"@andersonluisribeiro/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":"@andersonluisribeiro/iotagent-nodejs@2.1.0-beta.9","_npmVersion":"6.5.0","_nodeVersion":"11.9.0","_npmUser":{"name":"andersonluisribeiro","email":"anderson.luis.rib@gmail.com"},"dist":{"integrity":"sha512-f8KOc+jlZR17/v1gSB2G+/m8DD89bc8jojTLRb+QSnHQ0+FZp+7ODuDiLqVEvNAAPERIYF6Y8vNPIZZGCHmUSg==","shasum":"d015b92640c9a6dfb4129c442bd93061a8d1c45c","tarball":"https://registry.npmjs.org/@andersonluisribeiro/iotagent-nodejs/-/iotagent-nodejs-2.1.0-beta.9.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\nwsFcBAEBCAAQBQJeuqpSCRA9TVsSAnZWagAAgRQQAIYz0gRUugvjEl3mfX8V\nhNKHr2huolJ/K2Nb/rWOUwEgkNjm6yEmkUJAXsJznj/k4XHfks4k0OCL8Cwy\ns0DftaoWC/ZDzSCXxhYJL3q5E0Ob2BZKqqANnSq5CBIhsq8l944V+fLHgSo/\nmJJ2nM1YLNFtmenGnV1h/gkPcWmDfKtJqmeDoSN/BFTSwwlFxO2LS9XY/CPn\ntA95Ro4afn0DxeMZ191q9UGeaTLVitXmrcTo4XPRsEp8emiy1odOqRNQb7rq\nLb7kiXPqzQY5EvrsP48dtwLG99ZpMXOUwt+D97bLEDNYjMN/Skyu8zeI0x1K\nDqDGh6/RPWqyDnLuX8tOZGcVYn/+EiPThJrH7ZSzf2fUU13yeUSzE/e+VGOC\n1vq9h/4vvcA/WH6ntSEmT1UwHhgQTfZZ6kUiD1nqO2DvVrByBZSSliZe5Np6\n+3tcaLb7w3BB2lm55+hz50Juy0qOE5lv88H3GCjxNTPaa19LiXd1/yl9/Z8O\nsDPNFYGOnW/jffAvN0n3TqSo/g8KRgk87UJgVNdSNhJBSQArB5cGSOJUw02S\nMNPOqN7LwLhJShNp31LqdK7yz2c/didmPXBe29+nDYz8/qI+au8qkI1bzlkj\nKSOTY7QIR134oNzchvKs+L99Y8D6cIkGo5chljT6g+TYDpJA/zKwB8HqQXB2\na+pr\r\n=eUe+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDkcTitXennh87O4oec+kRmidOv2usvkBymcuvE190L5QIgAzRYm6q0JwCDiBNQyKNhGyS1dNtA9igJVozfn0P+xTw="}]},"maintainers":[{"name":"andersonluisribeiro","email":"anderson.luis.rib@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/iotagent-nodejs_2.1.0-beta.9_1589291601936_0.14319699039154576"},"_hasShrinkwrap":false},"2.1.0-beta.10":{"name":"@andersonluisribeiro/iotagent-nodejs","version":"2.1.0-beta.10","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":"@andersonluisribeiro/iotagent-nodejs@2.1.0-beta.10","_npmVersion":"6.5.0","_nodeVersion":"11.9.0","_npmUser":{"name":"andersonluisribeiro","email":"anderson.luis.rib@gmail.com"},"dist":{"integrity":"sha512-OqnZHjTECFPh37yjJUWp4RlUiK9GfrvMfvckFe98juFI2HkzEF/og4wl+ikhhuq9pyMuULum7qswoB0X4uXKdA==","shasum":"fd7e2e74efcfeeed757b46ae9814702ae821a7e0","tarball":"https://registry.npmjs.org/@andersonluisribeiro/iotagent-nodejs/-/iotagent-nodejs-2.1.0-beta.10.tgz","fileCount":11,"unpackedSize":52422,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeuvpLCRA9TVsSAnZWagAAKdgP+wX8tawv93DhhGNGHDcC\nDrwYZVdhoZ0l1NRa9ZuxhfxDScgqskahQJQ+ItC/uCHv2qAa1jryxIIrmI+i\n5ArjXB+Pb1EEHzrAvZi2iDowLGMtS/vkFxLe7p3476JzJDQl0S0h7A5fjoG/\nbaSGYbQlRIRckR+GqB4KpYYXnGHujxpt1JyMO6bn1gS5xO773M7emWChovDR\nd2CfkJxbhV+aSOl29t31YI6gyb8NLQQRbztP4XLkPOUYTG5UtvGcRJ0tyUTR\n62G2/TPFtCKE5+P/63CRNCIRg6vDMwN3dU4r1I+9449FZozcFqHJSxGT2gWS\nqvmbG/DxLxgI0QSqa1tJJqjbZFQeUIyk7DEVQo2hmBOhuKXYFAl7AIeXy/Wd\nUTMxqIKHadNm3WFwTTXsdR12iVlq6c+VIh8lC3YJdytn4FNXTbkzUF/adXm6\nZtKF1nQK36QVSiROk6q8w+9gXVtExePzfWfuYCa2pn3Os4PJ8+k7q2lkgzZY\njq5RSz8VTyo5Nti6NOsqNJlYQHTx/PMq3K9cuQ/VlE+/9XIIvW9jo60D9eYv\ntltrWF24fyOwN+T/nOnlypDd0X0QnRDKK4fpLbyOTqUk+qZY3ehcg2H4Ak7b\n8U4nBNFswG3c7slP34kCR8QuEcDE30WTvxdYEl4wQvU6m9jWeOlQlHvdxYL3\nQ8CT\r\n=b9BS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAfwFPqfksqBvk6jN0G5bHlfxtw8OniT2BxqdSXwetPrAiArG6CB/RTm0U7/URSdO6+tSIjnF+CFj2cbPDRTVRD4jQ=="}]},"maintainers":[{"name":"andersonluisribeiro","email":"anderson.luis.rib@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/iotagent-nodejs_2.1.0-beta.10_1589312075199_0.7152761941661372"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-12T13:53:21.894Z","2.1.0-beta.9":"2020-05-12T13:53:22.036Z","modified":"2022-04-04T13:58:07.514Z","2.1.0-beta.10":"2020-05-12T19:34:35.346Z"},"maintainers":[{"name":"andersonluisribeiro","email":"anderson.luis.rib@gmail.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"}