# Data logging simulation using modsim to postgreSQL via nodered

**URL:** https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388
**Category:** General
**Tags:** function-node
**Created:** [30 July 2025 07:54 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388 "2025-07-30T07:54:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [30 July 2025 07:54 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/1 "2025-07-30T07:54:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 July 2025 08:14 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/2 "2025-07-30T08:14:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [30 July 2025 08:21 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/3 "2025-07-30T08:21:56Z")

</div>

_ **Send data from modsim** _  
30/7/2025, 15.18.56[node: debug 100](http://127.0.0.1:1880/#)INSERT INTO tabela(data1, data2) VALUES($1, $2) : msg.payload : array[0]

[_empty_]

then, _ **insert manual** _  
30/7/2025, 15.29.42[node: debug 1](http://127.0.0.1:1880/#)msg.payload : array[0]

[empty]

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [30 July 2025 08:35 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/4 "2025-07-30T08:35:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [31 July 2025 03:37 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/5 "2025-07-31T03:37:25Z")

</div>

of course, this is complete debug output message

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b3b4185aeb0c330a0598a6487ed382a06792c01.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [31 July 2025 05:38 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/6 "2025-07-31T05:38:49Z")

</div>

You have not stated which postgres node you are using so assuming you are using this one: [node-red-contrib-postgresql (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-postgresql) then it is `msg.params` not `msg.parameters `

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [31 July 2025 06:39 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/7 "2025-07-31T06:39:10Z")

</div>

Idk which postgree node this one.  
Here my work flow

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/d/1db8aa0a2d25d71e26b64e66930e372f299ad618.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [31 July 2025 08:07 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/8 "2025-07-31T08:07:21Z")

</div>

Look in Manage Palette to see which node you have installed. Also make sure there is only on postgress node installed.

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [31 July 2025 08:09 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/9 "2025-07-31T08:09:05Z")

</div>

# using this one node-red-contrib-postgresql

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [31 July 2025 08:09 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/10 "2025-07-31T08:09:55Z")

</div>

i’ve already change to msg.params to, but still not working

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [31 July 2025 08:15 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/11 "2025-07-31T08:15:36Z")

</div>

> [@hafizhshafi](#):
>
> but still not working

Without details, no one can help 😉

Do you get an error? What is shown in the debug node output?

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [31 July 2025 08:19 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/12 "2025-07-31T08:19:27Z")

</div>

INSERT INTO public.tabel4 (tag\_name, nilai, waktu) VALUES ('KPPJBS/PLTMG\_BauBau/Unit\_4/Exh gas temp de... : msg : Object

_object_

topic: _string_

```auto
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_

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [31 July 2025 08:21 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/13 "2025-07-31T08:21:55Z")

</div>

Is that from debug 3?

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [31 July 2025 08:27 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/14 "2025-07-31T08:27:32Z")

</div>

yes sir …

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [31 July 2025 08:41 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/15 "2025-07-31T08:41:28Z")

</div>

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;

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [31 July 2025 10:17 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/16 "2025-07-31T10:17:07Z")

</div>

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!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/753277641ab9dfd5e945b25e841ead8a7974020d.png)

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [1 August 2025 00:56 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/17 "2025-08-01T00:56:11Z")

</div>

After change to msg.params still not working sir

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [1 August 2025 01:03 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/18 "2025-08-01T01:03:20Z")

</div>

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;

---

<div class="post-metadata">

### Author: ![hafizhshafi](https://avatars.discourse-cdn.com/v4/letter/h/d26b3c/32.png) [@hafizhshafi](https://discourse.nodered.org/u/hafizhshafi)
#### Post date: [1 August 2025 01:05 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/19 "2025-08-01T01:05:14Z")

</div>

But the table i create from node-red was succesfully inject to DB. So confunsing sir 😃

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [30 October 2025 01:05 UTC](https://discourse.nodered.org/t/data-logging-simulation-using-modsim-to-postgresql-via-nodered/98388/20 "2025-10-30T01:05:29Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
