I just recently used Node-red. I created a function that can save to local postgres using node-red-contrib-postgres-multi package
I have a data from my mqtt client:
msg.topic = 'data'
msg.payload = [
{ key: 'pumpingstation', value: '0.00' },
{ key: 'centrifuge', value: '21.08' },
{ key: 'Dafpump1', value: '5.20' },
{ key: 'Dafpump2', value: '23.10' }
]
in my function node it look like this:
var topic1 = msg.topic;
var payload1 = msg.payload;
msg.payload = [
{
query: 'INSERT INTO mqtt_table (topic, payload) values (1, $topic), (2, $payload)',
params: {
topic: topic1,
payload: payload1,
},
},
{
query: 'commit',
},
];
// Return the modified message
return msg;
and in my postgres node I have set up my credentials correctly. There's no error but it's not saving to my database. Is there something wrong with my process? Let me know if my question is not clear. Thanks!
