[ { "id": "77c0b0db.f71e2", "type": "function", "z": "967d3855.7d32d8", "name": "Flatten Array", "func": "//this function un-nests or \"flattens\" the arrays (they get nested as a result of the join node) \n//so that they can be ingested by the MindSphere node\nfor (var i = 0; i < msg.payload.length; i++) {\n msg.payload[i] = msg.payload[i][0]; \n}\nreturn msg;", "outputs": 1, "noerr": 0, "x": 799.3333930969238, "y": 276.33334159851074, "wires": [ [ "b5b1d7e6.b49708" ] ] }, { "id": "f2ddb4ae.130748", "type": "function", "z": "967d3855.7d32d8", "name": "Value_prep", "func": "//Creates packets of data that are formatted for the MindSphere node to ingest\n if (!Date.prototype.toISOString) {\n (function() {\n \n function pad(number) {\n if (number < 10) {\n return '0' + number;\n }\n return number;\n }\n \n Date.prototype.toISOString = function() {\n return this.getUTCFullYear() +\n '-' + pad(this.getUTCMonth() + 1) +\n '-' + pad(this.getUTCDate()) +\n 'T' + pad(this.getUTCHours()) +\n ':' + pad(this.getUTCMinutes()) +\n ':' + pad(this.getUTCSeconds()) +\n '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +\n 'Z';\n };\n \n }());\n }\n\n\n\nconst values = [];\nvar i = 0;\nfor(i; i < msg.payload.length;i++){\n if(msg.payload[i].type == \"Load\"){\n values.push( {\n \"timestamp\":new Date().toISOString(),\n \"values\":[{ \"dataPointId\": \"1563758691383\", \"qualityCode\": \"1\", \"value\": (Math.random()*100).toString() }]\n });\n }else if(msg.payload[i].type == \"Speed\"){\n values.push({\n \"timestamp\": new Date().toISOString(),\n \"values\":[{ \"dataPointId\": \"1563758722040\", \"qualityCode\": \"1\", \"value\": (Math.random()*100).toString() }]\n });\n }else if(msg.payload[i].type == \"Temperature\"){\n values.push({\n \"timestamp\": new Date().toISOString(),\n \"values\":[{ \"dataPointId\": \"1563758709362\", \"qualityCode\": \"1\", \"value\": (Math.random()*100).toString() }]\n });\n }\n}\n\nmsg.payload = values; \n\nreturn msg;\n", "outputs": 1, "noerr": 0, "x": 487.3333435058594, "y": 276.3333406448364, "wires": [ [ "6b95097d.e3aef8" ] ] }, { "id": "b5b1d7e6.b49708", "type": "mindconnect", "z": "967d3855.7d32d8", "name": "", "configtype": "SHARED_SECRET", "agentconfig": "", "privatekey": "", "model": "", "validate": true, "validateevent": true, "chunk": false, "disablekeepalive": false, "retry": 3, "parallel": 1, "x": 848.666690826416, "y": 333.0001926422119, "wires": [ [ "422cad93.cb5f74" ] ] }, { "id": "f2020043.b13f2", "type": "function", "z": "967d3855.7d32d8", "name": "dataSim", "func": "msg.payload = [];\nvar max = 30;\nvar min = 0\nvar ran = Math.floor(Math.random() * (max - min + 1)) + min;\nif(ran <= 10){\n msg.payload.push({value : \"100\", type : \"Load\"});\n}\nelse if(ran <= 20){\n msg.payload.push({value : \"100\", type : \"Speed\"});\n}\nelse if(ran <= 30){\n msg.payload.push({value : \"100\", type : \"Temperature\"});\n}\nreturn msg;", "outputs": 1, "noerr": 0, "x": 316.00000762939453, "y": 278.00000762939453, "wires": [ [ "f2ddb4ae.130748" ] ] }, { "id": "6b95097d.e3aef8", "type": "join", "z": "967d3855.7d32d8", "name": "", "mode": "custom", "build": "array", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "accumulate": false, "timeout": "20", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 637.0000152587891, "y": 276.00000953674316, "wires": [ [ "77c0b0db.f71e2" ] ] }, { "id": "5e7d6cf.1fd8a94", "type": "inject", "z": "967d3855.7d32d8", "name": "", "topic": "", "payload": "", "payloadType": "date", "repeat": "3", "crontab": "", "once": true, "onceDelay": 0.1, "x": 118, "y": 277.00000762939453, "wires": [ [ "f2020043.b13f2" ] ] }, { "id": "422cad93.cb5f74", "type": "debug", "z": "967d3855.7d32d8", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 1086.0000305175781, "y": 334.00000953674316, "wires": [] } ]