How to send data from modbus to postgreSQL database via nodered ? i already try to send data manually from querry and its work, but its not working when i send the data which come from modsim
Welcome to the forum @hafizhshafi
If it works when you do it manually but not when fetching via modbus then the message you are sending to the db in the two cases must be different. Use Debug nodes to see what the difference is.
Send data from modsim
30/7/2025, 15.18.56node: debug 100INSERT INTO tabela(data1, data2) VALUES($1, $2) : msg.payload : array[0]
[empty]
then, insert manual
30/7/2025, 15.29.42node: debug 1msg.payload : array[0]
[ empty ]
Set the debug nodes Output Complete Message. Then it is easier to see what is in msg.payload and msg.topic.
However, you said that the insert manual works, but there doesn't appear to be any data to insert.
Also in the modsim message there doesn't appear to be an data.
You have not stated which postgres node you are using so assuming you are using this one: node-red-contrib-postgresql (node) - Node-RED then it is msg.params
not msg.parameters
Look in Manage Palette to see which node you have installed. Also make sure there is only on postgress node installed.
i’ve already change to msg.params to, but still not working
Without details, no one can help
Do you get an error? What is shown in the debug node output?
INSERT INTO public.tabel4 (tag_name, nilai, waktu) VALUES ('KPPJBS/PLTMG_BauBau/Unit_4/Exh gas temp de... : msg : Object
object
topic: string
INSERT INTO public.tabel4 (tag_name, nilai, waktu) VALUES ('KPPJBS/PLTMG_BauBau/Unit_4/Exh gas temp deviation cyl 04B TY5047B', 156, '2025-07-31T08:20:09.911Z')
qos: 2
retain: false
_msgid: "8a01ab6812ace118"
payload: array[0]
pgsql: object
command: null
rowCount: null
Is that from debug 3?
yes sir …
My function node :
const tagName = msg.topic;
const nilai = msg.payload;
const waktu = new Date().toISOString();
const sanitizedTagName = tagName.replace(/'/g, "''");
const sqlQuery = `INSERT INTO public.tabel4 (tag_name, nilai, waktu) VALUES ('${sanitizedTagName}', ${nilai}, '${waktu}')`;
msg.topic = sqlQuery;
delete msg.payload;
delete msg.parameters;
return msg;
You have changed how the insert was being done with parameters to using a SQL String. This is not good practice (open to SQL Injection hacks)
All you needed to do in your function was to rename msg.parameters
to msg.params
everything else was good!
After change to msg.params still not working sir
Like this
const tagName = msg.topic;
const nilai = msg.payload;
const waktu = new Date().toISOString();
const sanitizedTagName = tagName.replace(/'/g, "''");
const sqlQuery = `INSERT INTO public.tabel4 (tag_name, nilai, waktu) VALUES ('${sanitizedTagName}', ${nilai}, '${waktu}')`;
msg.topic = sqlQuery;
delete msg.payload;
delete msg.params;
return msg;
But the table i create from node-red was succesfully inject to DB. So confunsing sir