I have been working with Node Red and InfluxDB for only a couple of weeks and have run into some trouble.
My PLC sends data via MQTT in CSV format, and I have successfully parsed and injected a single row of data into InfluxDB. I have attempted to scale up to store multiple records simultaneously, though when I do so, Influx only seems to store the last record in the JSON array.
I have imported the demo flow on storing multiple records via an array of arrays and it seems to work fine. My parsing differs since I don't know how many records are being sent by any given system, so I have to dynamically create the JSON. I have verified the string's format using the JSON Parser node, and other than the data in the record, the format looks the same.
Influx only stores the last record in the array, record "Name2" in the current test data. If I add or remove a record it is always the last one that gets stored.
I've been fighting with this all day and am not sure where I've gone wrong.
Here is a copy of my flow:
[{"id":"b5a08af2.2ed918","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"2a0a3ef2.1901b2","type":"function","z":"b5a08af2.2ed918","name":"Parse 1 to 10 Bins of Data","func":"var bins = msg.payload.split(\";;\");\nvar jsonArray = [];\n\nbins.forEach(BinToJson);\nmsg.payload = jsonArray\nreturn msg;\n\n// function to parse data of individual bins\nfunction BinToJson(item, index){\n var tokens = item.split(\";\")\n var binData = [{\n BinID: tokens[0],\n OsaTemp: parseFloat(tokens[1]),\n PlenumTemp: parseFloat(tokens[2]),\n ReturnTemp: parseFloat(tokens[3]),\n Pile1: parseFloat(tokens[4]),\n Pile2: parseFloat(tokens[5]),\n Pile3: parseFloat(tokens[6]),\n Pile4: parseFloat(tokens[7]),\n Pile5: parseFloat(tokens[8]),\n Pile6: parseFloat(tokens[9]),\n OsaRh: parseFloat(tokens[10]),\n PlenumRh: parseFloat(tokens[11]),\n ReturnRh: parseFloat(tokens[12]),\n Co2: parseFloat(tokens[13]),\n time: new Date()\n }]\n \n jsonArray.push(binData);\n}","outputs":1,"noerr":0,"x":310,"y":100,"wires":[["c1875cd7.553a1","add867.8117c798","1c4f0221.f514ae"]]},{"id":"c1875cd7.553a1","type":"debug","z":"b5a08af2.2ed918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":710,"y":100,"wires":[]},{"id":"fde2780c.51fd98","type":"inject","z":"b5a08af2.2ed918","name":"Bin Test Data","topic":"","payload":"Name0;1;2;3;4;5;6;7;8;9;10;11;12;13;;Name1;14;15;16;17;18;19;20;21;22;23;24;25;26;;Name2;27;28;29;30;31;32;33;34;35;36;37;38;39","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"2","x":90,"y":100,"wires":[["2a0a3ef2.1901b2"]]},{"id":"e723c399.627c5","type":"function","z":"b5a08af2.2ed918","name":"Node-Red Multi-Row Demo","func":"msg.payload = [\n [{\n numValue: 10,\n randomValue: Math.random()*10,\n strValue: \"message1\",\n time: new Date(\"2015-12-28T19:41:13Z\").getTime()\n }],\n [{\n numValue: 20,\n randomValue: Math.random()*10,\n strValue: \"message2\",\n time: new Date(\"2015-12-28T19:41:14Z\").getTime()\n }]\n];\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":260,"wires":[["c46ddb8e.83dff8","1ded6713.815f79"]]},{"id":"e46a3f60.54e61","type":"inject","z":"b5a08af2.2ed918","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":96,"y":260,"wires":[["e723c399.627c5"]]},{"id":"c46ddb8e.83dff8","type":"influxdb out","z":"b5a08af2.2ed918","influxdb":"e9084128.38462","name":"","measurement":"test","precision":"","retentionPolicy":"","x":710,"y":260,"wires":[]},{"id":"add867.8117c798","type":"influxdb out","z":"b5a08af2.2ed918","influxdb":"e9084128.38462","name":"","measurement":"testing","precision":"","retentionPolicy":"","x":720,"y":60,"wires":[]},{"id":"1c4f0221.f514ae","type":"json","z":"b5a08af2.2ed918","name":"","property":"payload","action":"","pretty":false,"x":530,"y":140,"wires":[["c1875cd7.553a1"]]},{"id":"1ded6713.815f79","type":"json","z":"b5a08af2.2ed918","name":"","property":"payload","action":"","pretty":false,"x":530,"y":300,"wires":[["5995febf.456f9"]]},{"id":"5995febf.456f9","type":"debug","z":"b5a08af2.2ed918","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":300,"wires":[]},{"id":"e9084128.38462","type":"influxdb","z":"","hostname":"192.168.0.103","port":"8086","protocol":"http","database":"SensorData","name":"rPi DB","usetls":false,"tls":""}]
Thanks in advance.