node-red-contrib-mnubo 1.1.1

Mnubo

npm install node-red-contrib-mnubo

Table of Content

1. Introduction

2. Architecture

3. Pre-requisites

4. Installation & Configuration

5. Usage

6. Important notes

7. Source code

8. Known limitations

9. References


#1. Introduction

This is the implementation of the mnubo's SmartObjects functionality in the node-red environment.

Note that this package is also compatible with other node-red environments, like IBM Bluemix and AT&T Flow.


#2. Architecture

This is a front-end implementation of the https://www.npmjs.com/package/mnubo-sdk

Detailed info is available on the individual node in node-red.

Here is a brief description of the nodes:

mnubo config: This is the Configuration Node that holds the mnubo's SmartObjects credential, all nodes need to have this configured.

Auth: This node is used to fetch the access token for communication with SmartObject. This node will also allow you to get the status about the token.

Owners : This node is used to handle the Owners Ingestion API: Create, Update, Delete, Claim Object

Objects : This node is used to handle the Objects Ingestion API: Create, Update, Delete

Events : This node is used to handle the Events Ingestion API: Send, SendFromDevice

Analytics : This node is used to handle the Search API: getDataset, getDatamodel, SearchQurery


#3. Prerequisites

This is a node-red package, so it requires node-red, The minimum version of node-red supported is v0.10.10

To use the mnubo's SmartObjects nodes, you will need to have a valid mnubo account, with access granted on a namespace. To obtain your unique namespace in the SmartObjects platform, contact sales@mnubo.com . Please use the subject title node-red-contrinb-mnubo and include in the body of the email the name of your company, contact name and phone number.

Once logged into mnubo's SmartObjects, the Official reference API can be found in the following: [API documentation]

(https://sop.mtl.mnubo.com/apps/doc/?i=t).

This package also requires the following package:

  • mnubo's SmartObjects Javascript SDK mnubo-js-sdk
  • ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines es6-shim

Those packages will be installed automatically by npm, as they are dependent packages.


#4. Installation & Configuration

Linux installation

sudo npm install --prefix ~/.node-red node-red-contrib-mnubo

Windows installation (using Cygwin)

npm install --prefix ~/.node-red node-red-contrib-mnubo
mkdir %homepath%/.node-red/nodes
cp -rp %homepath%/node_modules/node-red-contrib-mnubo %homepath%/.node-red/nodes/

AT&T flow

Note that this node is also compatible with the AT&T Flow, to use it in flow, just edit the package.json in your flow project, and add this node in the depedency:

"dependencies":{"node-red-contrib-mnubo":"^1.0.3"}

    Then, when you will " enter the Online mode", you should have access to the mnubo nodes.

IBM Bluemix

TBD

#5. Usage

Examples

Example 1: Quick Demo

Here is a quick demo that shows how to authenticate, create owner, update owner, create object, update object, send event, do a basicSearchQuery,

delete the object, delete the owner:

[{"id":"ea597271.15a69","type":"mnubo config","z":"2d7a2cc9.d285d4","name":"Jerome","env":"sandbox","proxy_url":""},{"id":"17925606.e86daa","type":"mnubo auth","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","x":440,"y":56,"wires":[["561a8d39.a9e574"]]},{"id":"51b613ce.ae49ec","type":"inject","z":"2d7a2cc9.d285d4","name":"","topic":"Test All","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":95,"y":63,"wires":[["17925606.e86daa"]]},{"id":"e6b03005.194fd","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":924,"y":194,"wires":[]},{"id":"561a8d39.a9e574","type":"switch","z":"2d7a2cc9.d285d4","name":"Token != Bearer","property":"payload.token_type","rules":[{"t":"neq","v":"Bearer"},{"t":"eq","v":"Bearer"}],"checkall":"true","outputs":2,"x":646,"y":57,"wires":[["edd7671.f122898"],["9e5aef3.f61a51","7638564f.89c7a8"]]},{"id":"5aa31777.a55ce8","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":925,"y":163,"wires":[]},{"id":"9bbadf79.64452","type":"mnubo owners","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"create","inputtext":"","x":495,"y":169,"wires":[["cef1f5b4.310e08"]]},{"id":"dedbc5dd.212438","type":"mnubo owners","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"delete","inputtext":"","x":487,"y":845,"wires":[["20e69541.df196a"]]},{"id":"cef1f5b4.310e08","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":684,"y":170,"wires":[["5aa31777.a55ce8"],["e6b03005.194fd","8c56464e.73a9b8"]]},{"id":"edd7671.f122898","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":932,"y":44,"wires":[]},{"id":"9e5aef3.f61a51","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":930,"y":76,"wires":[]},{"id":"e27db47b.1d8248","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":916,"y":838,"wires":[]},{"id":"826e9923.7d9168","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":913,"y":870,"wires":[]},{"id":"5d93e52a.a26c1c","type":"inject","z":"2d7a2cc9.d285d4","name":"","topic":"clean","payload":"node-red-auto1@test.com","payloadType":"none","repeat":"","crontab":"","once":false,"x":90,"y":845,"wires":[["26751614.d98aea"]]},{"id":"8b0cf49c.74f308","type":"inject","z":"2d7a2cc9.d285d4","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":104,"y":115,"wires":[["7638564f.89c7a8"]]},{"id":"20e69541.df196a","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":707,"y":840,"wires":[["e27db47b.1d8248"],["826e9923.7d9168"]]},{"id":"2d1551a5.d2eaae","type":"mnubo owners","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"update","inputtext":"","x":485,"y":244,"wires":[["1ac7224c.e538de"]]},{"id":"2613a0df.d9ec6","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":924,"y":268,"wires":[]},{"id":"9a919985.656e68","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":924,"y":236,"wires":[]},{"id":"1ac7224c.e538de","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":754,"y":243,"wires":[["9a919985.656e68"],["2613a0df.d9ec6","59891fad.a676e"]]},{"id":"160827c6.e9f7d8","type":"mnubo objects","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"create","inputtext":"","x":484,"y":329,"wires":[["aecec38f.51314"]]},{"id":"aecec38f.51314","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":689,"y":328,"wires":[["7693bc16.896c44"],["5541f356.aabe0c","f6a1d851.095e28"]]},{"id":"7693bc16.896c44","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":923,"y":315,"wires":[]},{"id":"5541f356.aabe0c","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":923,"y":347,"wires":[]},{"id":"888d985f.777268","type":"mnubo objects","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"delete","inputtext":"","x":483,"y":767,"wires":[["c1c10f87.3e3ef"]]},{"id":"520a783b.adf588","type":"inject","z":"2d7a2cc9.d285d4","name":"","topic":"clean","payload":"node-red-auto1@test.com","payloadType":"none","repeat":"","crontab":"","once":false,"x":91,"y":769,"wires":[["a4cc7ee4.5b338"]]},{"id":"21ddd627.de222a","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":919,"y":747,"wires":[]},{"id":"118809d1.ee77f6","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":918,"y":779,"wires":[]},{"id":"c1c10f87.3e3ef","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":709,"y":757,"wires":[["21ddd627.de222a"],["118809d1.ee77f6","26751614.d98aea"]]},{"id":"bc053e9.f43fac","type":"mnubo objects","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"update","inputtext":"","x":474,"y":405,"wires":[["37638d74.c89c72"]]},{"id":"c1ce8353.3e318","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":921,"y":424,"wires":[]},{"id":"9dbfbc60.62404","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":921,"y":392,"wires":[]},{"id":"37638d74.c89c72","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":743,"y":405,"wires":[["9dbfbc60.62404"],["c1ce8353.3e318","ef9f73c3.10609"]]},{"id":"9f0aed7.f60f51","type":"mnubo events","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"send","inputtext":"","x":469,"y":481,"wires":[["f3f191c9.0c0e7"]]},{"id":"f45df5fa.0ba208","type":"mnubo events","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","functionselection":"sendfromdevice","inputtext":"[\n    \"node-red-device-auto1\", \n    [{\n\t\"x_event_type\": \"event_type_test\",\n\t\"x_timestamp\": \"2015-01-22T00:01:25-02:00\",\n\t\"x_latitude\": 57.876,\n\t\"x_longitude\": 57.876,\n\t\"temperature\": 15.2\n    }]\n]","x":522.5555572509766,"y":558.1110897064209,"wires":[["59c45d43.a63ba4"]]},{"id":"70b1e62a.8f4e18","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":922,"y":501,"wires":[]},{"id":"154891fb.eab76e","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":922,"y":469,"wires":[]},{"id":"f3f191c9.0c0e7","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":749,"y":483,"wires":[["154891fb.eab76e"],["70b1e62a.8f4e18","25c970e1.da369"]]},{"id":"bd682dca.4297d","type":"debug","z":"2d7a2cc9.d285d4","name":"OK","active":true,"console":"false","complete":"payload","x":920,"y":584,"wires":[]},{"id":"15ccba17.ea3346","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":920,"y":552,"wires":[]},{"id":"59c45d43.a63ba4","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":742,"y":559,"wires":[["15ccba17.ea3346"],["bd682dca.4297d","88f33cd9.770cc"]]},{"id":"30375974.cfc8a6","type":"mnubo analytics","z":"2d7a2cc9.d285d4","name":"","mnuboconfig":"ea597271.15a69","searchtype":"SearchQuery","inputquery":"","x":459,"y":658,"wires":[["cb2aaf90.34d55","a4cc7ee4.5b338"]]},{"id":"da542530.25abd8","type":"debug","z":"2d7a2cc9.d285d4","name":"Error","active":true,"console":"false","complete":"payload","x":920,"y":635,"wires":[]},{"id":"d55b7326.2aa49","type":"debug","z":"2d7a2cc9.d285d4","name":"rows","active":true,"console":"false","complete":"payload.rows","x":920,"y":667,"wires":[]},{"id":"cb2aaf90.34d55","type":"switch","z":"2d7a2cc9.d285d4","name":"errorCode is not null","property":"payload.errorCode","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","outputs":2,"x":705,"y":656,"wires":[["da542530.25abd8"],["d55b7326.2aa49"]]},{"id":"2be4304.fd41bd","type":"function","z":"2d7a2cc9.d285d4","name":"Create Owner","func":"msg.payload =\n{\n\t\"username\": context.global.mnubo.owner1,\n\t\"x_password\": \"12345678\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":319.4444694519043,"y":167.88886642456055,"wires":[["9bbadf79.64452"]]},{"id":"59891fad.a676e","type":"function","z":"2d7a2cc9.d285d4","name":"Create an Object","func":"msg.payload = {\n\t\"x_device_id\": context.global.mnubo.object1,\n\t\"x_object_type\": \"test\",\n\t\"x_owner\": {\n\t\t\"username\": context.global.mnubo.owner1\n\t}\n};\nreturn msg;","outputs":1,"noerr":0,"x":289.4444465637207,"y":330.11110496520996,"wires":[["160827c6.e9f7d8"]]},{"id":"ef9f73c3.10609","type":"function","z":"2d7a2cc9.d285d4","name":"Send an event","func":"msg.payload = [{\n\t\"x_object\": {\"x_device_id\": context.global.mnubo.object1},\n\t\"x_event_type\": \"event_type_test\",\n\t\"x_timestamp\": \"2015-01-22T00:01:25-02:00\",\n\t\"x_latitude\": 57.876,\n\t\"x_longitude\": 57.876,\n\t\"temperature\": 25.6\n}];\nreturn msg;","outputs":1,"noerr":0,"x":276.11113357543945,"y":483.44441986083984,"wires":[["9f0aed7.f60f51"]]},{"id":"88f33cd9.770cc","type":"function","z":"2d7a2cc9.d285d4","name":"Count Events","func":"msg.payload = {\n\t\"from\": \"event\",\n\t\"select\": [{\n\t\t\"count\": \"*\"\n\t}]\n};\nreturn msg;","outputs":1,"noerr":0,"x":227.22222518920898,"y":660.1111354827881,"wires":[["30375974.cfc8a6"]]},{"id":"8c56464e.73a9b8","type":"function","z":"2d7a2cc9.d285d4","name":"Update owner","func":"msg.payload = [ \n  context.global.mnubo.owner1, \n  { \n\t\"x_registration_latitude\": 45.223, \n\t\"x_registration_longitude\": 73.234 \n  }\n];\nreturn msg;","outputs":1,"noerr":0,"x":289.44443130493164,"y":245.6666488647461,"wires":[["2d1551a5.d2eaae"]]},{"id":"f6a1d851.095e28","type":"function","z":"2d7a2cc9.d285d4","name":"Update Object","func":"msg.payload = [\n    context.global.mnubo.object1, \n{ \n\t\"x_object_type\": \"test2\" \n}\n];\nreturn msg;\n","outputs":1,"noerr":0,"x":286.11111068725586,"y":406.7777976989746,"wires":[["bc053e9.f43fac"]]},{"id":"25c970e1.da369","type":"function","z":"2d7a2cc9.d285d4","name":"Send an Event FROM the object","func":"msg.payload = [\n    context.global.mnubo.object1, \n    [{\n\t\"x_event_type\": \"event_type_test\",\n\t\"x_timestamp\": \"2015-01-22T00:01:25-02:00\",\n\t\"x_latitude\": 57.876,\n\t\"x_longitude\": 57.876,\n\t\"temperature\": 15.2\n    }]\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":254.33331298828125,"y":540.7777709960938,"wires":[["f45df5fa.0ba208"]]},{"id":"7638564f.89c7a8","type":"function","z":"2d7a2cc9.d285d4","name":"set global env","func":"var mnubo = new Object();\nmnubo.owner1 = \"node-red-auto1@test.com\"\nmnubo.object1 = \"node-red-device-auto1\"\n\n//Global context share by all functions\ncontext.global.mnubo = mnubo\n\nreturn msg;","outputs":1,"noerr":0,"x":327,"y":116,"wires":[["2be4304.fd41bd"]]},{"id":"26751614.d98aea","type":"function","z":"2d7a2cc9.d285d4","name":"delete owner1","func":"msg.payload = context.global.mnubo.owner1\nreturn msg;","outputs":1,"noerr":0,"x":267,"y":848,"wires":[["dedbc5dd.212438"]]},{"id":"a4cc7ee4.5b338","type":"function","z":"2d7a2cc9.d285d4","name":"delete owner1","func":"msg.payload = context.global.mnubo.object1\nreturn msg;","outputs":1,"noerr":0,"x":265,"y":769,"wires":[["888d985f.777268"]]},{"id":"a23c57f8.5dc3a8","type":"inject","z":"2d7a2cc9.d285d4","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":88,"y":169,"wires":[["2be4304.fd41bd"]]}]

### Example 2: Wind turbine demo

[{"id":"6da252cf.925dac","type":"mnubo config","z":"948e373d.6b71c8","name":"Jerome","env":"sandbox","proxy_url":""},{"id":"a9632fb8.569cd","type":"mnubo owners","z":"948e373d.6b71c8","name":"","mnuboconfig":"6da252cf.925dac","functionselection":"create","inputtext":"","x":586.0994110107422,"y":150,"wires":[["f3d3ce4.f0c2c3"]]},{"id":"f3d3ce4.f0c2c3","type":"debug","z":"948e373d.6b71c8","name":"","active":true,"console":"false","complete":"false","x":759.0994262695312,"y":169,"wires":[]},{"id":"68d0546f.972fac","type":"mnubo objects","z":"948e373d.6b71c8","name":"","mnuboconfig":"6da252cf.925dac","functionselection":"create","inputtext":"","x":588.0994262695312,"y":192,"wires":[["f3d3ce4.f0c2c3"]]},{"id":"ed9133e0.126ed","type":"function","z":"948e373d.6b71c8","name":"Create an Wind Turbine","func":"msg.payload = {\n \"x_device_id\": \"\"+context.global.deviceid+\"\",\n \"x_object_type\": \"windturbine\",\n \"x_owner\":{\"username\":\"\"+context.global.owner+\"\"},\n \"country\": \"Canada\", \n \"high\": \"85.0\", \n \"make\": \"Vestas\", \n \"max_power_output\": 2.0, \n \"model\": \"V90-2.0\", \n \"rotor_diameter\": 90.0, \n \"swept_area\": 6362.0,\n \"x_registration_latitude\": 45.4838, \n \"x_registration_longitude\": -73.5622 \n};\n\nreturn msg;","outputs":1,"x":369.09942626953125,"y":190,"wires":[["68d0546f.972fac"]]},{"id":"d7237681.28dc88","type":"inject","z":"948e373d.6b71c8","name":"","topic":"Create Object","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":157.09942626953125,"y":190,"wires":[["ed9133e0.126ed"]]},{"id":"4465482c.bb9ab8","type":"function","z":"948e373d.6b71c8","name":"Create an Owner","func":"msg.payload = {\n \"username\": \"\"+context.global.owner+\"\", \n \"x_password\": \"\"+context.global.owner+\"\"\n};\n\nreturn msg;","outputs":1,"x":369.09942626953125,"y":146,"wires":[["a9632fb8.569cd"]]},{"id":"3c969ce5.c36964","type":"inject","z":"948e373d.6b71c8","name":"","topic":"Create an Owner","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":168.09942626953125,"y":145,"wires":[["4465482c.bb9ab8"]]},{"id":"1f4552a3.e0baad","type":"inject","z":"948e373d.6b71c8","name":"","topic":"Delete Owner","payload":"node-red-auto1@test.com","payloadType":"none","repeat":"","crontab":"","once":false,"x":158.59942626953125,"y":341,"wires":[["91628b30.6e9d78"]]},{"id":"5e51ed5c.a1ae14","type":"mnubo owners","z":"948e373d.6b71c8","name":"","mnuboconfig":"6da252cf.925dac","functionselection":"delete","inputtext":"","x":538.5994262695312,"y":340,"wires":[["b5684959.4a97b8"]]},{"id":"b5684959.4a97b8","type":"debug","z":"948e373d.6b71c8","name":"","active":true,"console":"false","complete":"false","x":718.5994262695312,"y":315,"wires":[]},{"id":"7ca2ab66.835d54","type":"mnubo objects","z":"948e373d.6b71c8","name":"","mnuboconfig":"6da252cf.925dac","functionselection":"delete","inputtext":"","x":540.5994262695312,"y":290,"wires":[["b5684959.4a97b8"]]},{"id":"b84d636.f47b2a","type":"inject","z":"948e373d.6b71c8","name":"","topic":"Delete Object","payload":"node-red-auto1@test.com","payloadType":"none","repeat":"","crontab":"","once":false,"x":156.59942626953125,"y":289,"wires":[["233459a6.dccba6"]]},{"id":"2d029cd5.d2fd64","type":"comment","z":"948e373d.6b71c8","name":"Delete","info":"","x":109.09942626953125,"y":241,"wires":[]},{"id":"e6079c33.19f86","type":"debug","z":"948e373d.6b71c8","name":"","active":true,"console":"false","complete":"false","x":495.09942626953125,"y":579,"wires":[]},{"id":"cd631963.329ce8","type":"inject","z":"948e373d.6b71c8","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":140.09942626953125,"y":462,"wires":[["91d271b8.6e2d9"]]},{"id":"91d271b8.6e2d9","type":"function","z":"948e373d.6b71c8","name":"Read last sample","func":"msg.payload = {\n \"from\": \"event\",\n \"limit\":1,\n \"select\": [\n {\"VALUE\": \"x_timestamp\" },\n \t\t{\"VALUE\":\"instant_output_power\"}, \n \t\t{\"VALUE\":\"wind_speed\"} \n\t\t],\n\t\"where\":{\n\t \"and\":[\n\t {\"x_object.x_device_id\":{\"eq\":\"\"+context.global.deviceid+\"\"}}\n\t ]\n\t },\n\t\"orderBy\": [\n {\"value\": \"x_timestamp\", \"direction\": \"desc\"}\n ]\n};\n\nreturn msg;","outputs":1,"x":326.09942626953125,"y":462,"wires":[["4cbd32ca.b342cc"]]},{"id":"4cbd32ca.b342cc","type":"mnubo analytics","z":"948e373d.6b71c8","name":"","mnuboconfig":"6da252cf.925dac","searchtype":"SearchQuery","inputquery":"","x":571.0994262695312,"y":461,"wires":[["a3929edc.5c6d6"]]},{"id":"cf54b500.30ab48","type":"function","z":"948e373d.6b71c8","name":"Set Global Variables","func":"// set global variables\ncontext.global.owner = \"nodered\";\ncontext.global.deviceid = \"nodered-windturbine\";\n\nreturn msg;","outputs":1,"noerr":0,"x":320.09942626953125,"y":47,"wires":[[]]},{"id":"233459a6.dccba6","type":"function","z":"948e373d.6b71c8","name":"Set Device ID","func":"msg.payload = \"\"+context.global.deviceid+\"\";\nreturn msg;","outputs":1,"x":339.09942626953125,"y":289,"wires":[["7ca2ab66.835d54"]]},{"id":"91628b30.6e9d78","type":"function","z":"948e373d.6b71c8","name":"Set Owner","func":"msg.payload = \"\"+context.global.owner+\"\";\nreturn msg;","outputs":1,"x":333.09942626953125,"y":340,"wires":[["5e51ed5c.a1ae14"]]},{"id":"4dcb4942.b234b8","type":"function","z":"948e373d.6b71c8","name":"Read last sample","func":"var data = JSON.parse(msg.payload);\n\nvar output_power = data.rows[0][1];\nvar wind_speed = data.rows[0][2];\n\ncontext.global.output_power = output_power;\ncontext.global.wind_speed = wind_speed;\n\nmsg.payload = {\n \"from\": \"object\",\n \"select\": [\n {\"VALUE\": \"model\" },\n \t\t{\"VALUE\": \"x_owner.username\"} \n\t\t],\n\t\"where\":{\n\t \"and\":[\n\t {\"x_device_id\":{\"eq\":\"\"+context.global.deviceid+\"\"}}\n\t ]\n\t },\n};\n\nreturn msg;","outputs":1,"x":313.09942626953125,"y":520,"wires":[["17397a96.e8c685"]]},{"id":"17397a96.e8c685","type":"mnubo analytics","z":"948e373d.6b71c8","name":"","mnuboconfig":"6da252cf.925dac","searchtype":"SearchQuery","inputquery":"","x":559.0994262695312,"y":522,"wires":[["a5e5d0d9.5a1a3"]]},{"id":"a5e5d0d9.5a1a3","type":"json","z":"948e373d.6b71c8","name":"","x":744.0994262695312,"y":522,"wires":[["ecc9fe27.1336"]]},{"id":"ecc9fe27.1336","type":"function","z":"948e373d.6b71c8","name":"Read last sample","func":"var data = JSON.parse(msg.payload);\n\nvar model = data.rows[0][0];\nvar username = data.rows[0][1];\n\nmsg.payload = {\n \"Output Power\": context.global.output_power,\n \"Wind Speed\": context.global.wind_speed,\n \"Model\": model,\n \"Username\": username\n};\nreturn msg;","outputs":1,"x":308.09942626953125,"y":579,"wires":[["e6079c33.19f86"]]},{"id":"e201a3ce.1dfe6","type":"inject","z":"948e373d.6b71c8","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":true,"x":133.09942626953125,"y":47,"wires":[["cf54b500.30ab48"]]},{"id":"a3929edc.5c6d6","type":"json","z":"948e373d.6b71c8","name":"","x":757.0994262695312,"y":459,"wires":[["4dcb4942.b234b8"]]},{"id":"72e944a3.8d16bc","type":"comment","z":"948e373d.6b71c8","name":"Build \"Last events\" secction","info":"","x":170.09942626953125,"y":404,"wires":[]},{"id":"431e3078.bce1d","type":"comment","z":"948e373d.6b71c8","name":"\"MAP\" -- Total Output Power","info":"","x":173.09942626953125,"y":642,"wires":[]},{"id":"2a8187f0.d57e78","type":"debug","z":"948e373d.6b71c8","name":"","active":true,"console":"false","complete":"false","x":754.0994262695312,"y":699,"wires":[]},{"id":"9be5dcc7.641a2","type":"inject","z":"948e373d.6b71c8","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":133.09942626953125,"y":698,"wires":[["a617ca4d.59e838"]]},{"id":"a617ca4d.59e838","type":"function","z":"948e373d.6b71c8","name":"Read last sample","func":"msg.payload = {\n \"from\": \"event\",\n \"select\": [\n {\"SUM\": \"instant_output_power\" } \n\t\t],\n\t\"groupBy\": [\n\t\"x_object.x_registration_country_iso_code\"\n ]\n};\n\nreturn msg;","outputs":1,"x":317.09942626953125,"y":699,"wires":[["d2c5c61f.2d3a38"]]},{"id":"d2c5c61f.2d3a38","type":"mnubo analytics","z":"948e373d.6b71c8","name":"","mnuboconfig":"6da252cf.925dac","searchtype":"SearchQuery","inputquery":"","x":557.0994262695312,"y":699,"wires":[["2a8187f0.d57e78"]]},{"id":"9c5724d5.63a8d8","type":"comment","z":"948e373d.6b71c8","name":"Create","info":"","x":109.09942626953125,"y":103,"wires":[]}]```

```

#6. Important notes

The nodes were renamed between version 1.0.5 and 1.1.1, if you want to convert your flow, you can edit your flows (usually in ~/.node-red/flows_$HOSTNAME.json) you created in version 1.0.5 (or less), and replace the following:

Replace To
"type":"SmartObjects auth" "type":"mnubo auth"
"type":"SmartObjects analytics" "type":"mnubo analytics"
"type":"SmartObjects events" "type":"mnubo events"
"type":"SmartObjects objects" "type":"mnubo objects"
"type":"SmartObjects owners" "type":"mnubo owners"

#7. Source code

npm path: https://www.npmjs.com/package/node-red-contrib-mnubo

mnubo github sub path: https://github.com/mnubo/node-red-contrib-mnubo/tree/master/nodes/mnubo


#8. Known limitations

N/A


#9. References

https://www.npmjs.com/package/mnubo-sdk

http://nodered.org/

https://github.com/node-red/node-red

https://sop.mtl.mnubo.com/apps/doc/?i=t

Node Info

Version: 1.1.1
Updated 1 year, 3 months ago
License: MIT

Downloads

30 in the last day
71 in the last week
99 in the last month

Nodes

  • mnubo config
  • mnubo auth
  • mnubo analytics
  • mnubo owners
  • mnubo objects
  • mnubo events

Keywords

  • node-red
  • mnubo
  • api
  • sdk
  • javascript
  • typescript
  • iot
  • smartobject

Maintainers

  • jerome.langlais