First I must say what a great platform Node Red is and congratulations to the builders.
As a retired old man and with only 12 months programming experience I have just ventured into MQTT, MYSQL and now Node Red, I have successfully got several sensors in my home coupled to a local server running on an Rpi4b and saving the data on an mySql database.
The data from the sensors come in at different intervals, I'm currently using a Join node to combine the data as an array and then use this array to put the corresponding data into the correct db columns. This works okay, BUT sometimes (I'm not sure why) the value position in the array changes so the data is not inserted correctly.
I think I should be using the message topics somehow but having read endless posts and instructions I just cannot work out how to do it.
Any advice would be greatly appreciated.
[{"id":"b81988ca.7f1d68","type":"join","z":"b06d38d5.2a2e48","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":560,"wires":[["f6b37364.99938","d340b818.f387c8"]]},{"id":"f6b37364.99938","type":"debug","z":"b06d38d5.2a2e48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":520,"wires":[]},{"id":"49355e6a.850b","type":"mqtt in","z":"b06d38d5.2a2e48","name":"","topic":"IAQ/0999/temperature","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":160,"y":480,"wires":[["b81988ca.7f1d68"]]},{"id":"76c46ba1.e2c7d4","type":"mqtt in","z":"b06d38d5.2a2e48","name":"","topic":"IAQ/0999/humidity","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":150,"y":520,"wires":[["b81988ca.7f1d68"]]},{"id":"2ecf8a23.4e7086","type":"mqtt in","z":"b06d38d5.2a2e48","name":"","topic":"IAQ/0999/pm25","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":140,"y":560,"wires":[["b81988ca.7f1d68"]]},{"id":"2b367ee4.126c92","type":"mqtt in","z":"b06d38d5.2a2e48","name":"","topic":"IAQ/0999/count","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":140,"y":640,"wires":[["b81988ca.7f1d68"]]},{"id":"b2f7d3d4.57db5","type":"mqtt in","z":"b06d38d5.2a2e48","name":"0999 CO2","topic":"IAQ/0999/co2","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":120,"y":600,"wires":[["b81988ca.7f1d68"]]},{"id":"20042d51.e67242","type":"mysql","z":"b06d38d5.2a2e48","mydb":"3d3884d0.e0a06c","name":"","x":700,"y":580,"wires":[[]]},{"id":"d340b818.f387c8","type":"function","z":"b06d38d5.2a2e48","name":"INSERT Data","func":"temp = msg.payload[0];\nhum = msg.payload[1];\npm25 = msg.payload[2];\nco2 = msg.payload[4];\nif(msg.payload[3] === \"6\") {\nmsg.topic=\"INSERT INTO AP20999(value1, value2, value3,value4) VALUES(\"+pm25+\",\"+temp+\",\"+hum+\",\"+co2+\")\";\n\nreturn msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":580,"wires":[["20042d51.e67242"]]},{"id":"8db3fac0.99dd48","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"3d3884d0.e0a06c","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"IAQ","tz":"","charset":"UTF8"}]
Richard