Hi zenofmud,
Thank you for your input!
I apologize for that. I will add those points into my question right away!
- The platform on which I'm using Node Red is Windows 7 Home Premium.
- The Node-RED version I'm using is v0.19.4, whereas the node.js version is v8.12.0
- The nodes I'm using is node-red-contrib-influxdb
3,5. I have solved the problem The code is provided below.
The code works fine. I have attached a debug node and it shows that it has successfully created a string like the example. The problem is, when I try to input the generated string into "influxdb out", it refused to create a 12 rows, 5 columns database, instead it only created a row, and 2 columns with the first column being the timestamp when the string is injected, and the second column being the generated string.
=====Solution====
But anyway after mulling for some time, I have finally found the solution! Turned out the string has to be converted to JSON first before going to the database so I had to put a JSON node before the influxdb out node. Here's the code:
[{"id":"eebd77d4.12ae28","type":"tab","label":"input multiple data to influxDB manually","disabled":false,"info":"Example for node-red forum"},{"id":"f1d4b488.912018","type":"inject","z":"eebd77d4.12ae28","name":"inject data (JSON)","topic":"","payload":"{\"t\":[1548832805642,1548833525464,1548834375577],\"k1\":[1,0,0],\"k2\":[1,0,1],\"k3\":[1,0,0],\"k4\":[1,1,1],\"k5\":[0,0,0]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":166,"y":77,"wires":[["6991807f.01aa8"]]},{"id":"6991807f.01aa8","type":"function","z":"eebd77d4.12ae28","name":"input multiple data to influxDB","func":"content = msg.payload;\nn = 3 //number of data\n\nvar buffer;\nbuffer = \"[\";\n for(var i = 0; i < n; i++){\n if(i < (n-1)){\n buffer += \"[ \\\n { \\\n \\\"time\\\":\" + content.t[i] + \", \\\n \\\"k1\\\":\" + content.k1[i] + \", \\\n \\\"k2\\\":\" + content.k2[i] + \", \\\n \\\"k3\\\":\" + content.k3[i] + \", \\\n \\\"k4\\\":\" + content.k4[i] + \", \\\n \\\"k5\\\":\" + content.k5[i] + \" \\\n } \\\n ],\"\n } else{\n buffer += \"[ \\\n { \\\n \\\"time\\\":\" + content.t[i] + \", \\\n \\\"k1\\\":\" + content.k1[i] + \", \\\n \\\"k2\\\":\" + content.k2[i] + \", \\\n \\\"k3\\\":\" + content.k3[i] + \", \\\n \\\"k4\\\":\" + content.k4[i] + \", \\\n \\\"k5\\\":\" + content.k5[i] + \" \\\n } \\\n ]\"\n }\n }\nbuffer += \"]\";\n\nmsg.payload = buffer;\nreturn msg;\n\n/* Message payload will be:\n\"[[ { time:1548832805642, k1:1, k2:1, k3:1, k4:1, k5:0 } ],[ { time:1548833525464, k1:0, k2:0, k3:0, k4:1, k5:0 } ],[ { time:1548834375577, k1:0, k2:1, k3:0, k4:1, k5:0 } ]]\"\n\nReformatted for easy reading:\n\"[\n [\n { \n time:1548832805642, \n k1:1, \n k2:1, \n k3:1, \n k4:1, \n k5:0 \n }\n ],\n [ \n { \n time:1548833525464, \n k1:0, \n k2:0, \n k3:0, \n k4:1, \n k5:0 \n } \n ],\n [ \n { \n time:1548834375577, \n k1:0, \n k2:1, \n k3:0, \n k4:1, \n k5:0 \n } \n ]\n]\"\n*/","outputs":1,"noerr":0,"x":447,"y":77,"wires":[["a7f5b1d.1cc6f5","a153f08b.adff"]]},{"id":"a7f5b1d.1cc6f5","type":"debug","z":"eebd77d4.12ae28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":838,"y":20,"wires":[]},{"id":"d0363093.c8a46","type":"influxdb out","z":"eebd77d4.12ae28","influxdb":"a5f8b61d.9ff568","name":"","measurement":"data","precision":"","retentionPolicy":"","x":912,"y":76,"wires":[]},{"id":"4c301c5a.b9a004","type":"influxdb out","z":"eebd77d4.12ae28","influxdb":"a5f8b61d.9ff568","name":"","measurement":"example","precision":"","retentionPolicy":"","x":679,"y":226,"wires":[]},{"id":"3bef82df.e336ee","type":"function","z":"eebd77d4.12ae28","name":"input 2 row of data manually","func":"//REFERENCE: inputting 2 row of data manually ======================\nmsg.payload = [\n [\n {\n numValue: 20,\n randomValue: Math.random()*10,\n strValue: \"message1\",\n time: new Date(\"2015-12-28T19:41:13Z\").getTime()\n }\n ],\n [\n {\n numValue: 30,\n randomValue: Math.random()*10,\n strValue: \"message2\",\n time: new Date(\"2015-12-28T19:41:14Z\").getTime()\n }\n ]\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":352,"y":226,"wires":[["4c301c5a.b9a004","faa6f6b3.6594b8"]]},{"id":"fb01f719.c1a2f8","type":"inject","z":"eebd77d4.12ae28","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":131,"y":226,"wires":[["3bef82df.e336ee"]]},{"id":"a6d12d7e.b8396","type":"comment","z":"eebd77d4.12ae28","name":"Example from nodered.org","info":"URL:\nhttps://flows.nodered.org/node/node-red-contrib-influxdb","x":161,"y":175,"wires":[]},{"id":"faa6f6b3.6594b8","type":"debug","z":"eebd77d4.12ae28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":601,"y":182,"wires":[]},{"id":"a153f08b.adff","type":"json","z":"eebd77d4.12ae28","name":"","property":"payload","action":"","pretty":false,"x":664,"y":76,"wires":[["a7f5b1d.1cc6f5","d0363093.c8a46"]]},{"id":"a5f8b61d.9ff568","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"test_dellater2","name":"","usetls":false,"tls":""}]
Thank you for your help!