Send variables from Node Red to MySql

2,258 views
Skip to first unread message

Folke Haglund

unread,
Jan 5, 2018, 2:19:42 PM1/5/18
to Node-RED
Hello,

I would like to send the value of 3 variables, Energ1, Energy2 and Energy3, which are in a function node to columns KWh1, KWh2 and KWh3 in Mysql.
I have tried the "INSERT INTO ...", but I can't  get it to work.
Is there anyone who can help me?

Best Regards
Folke
Message has been deleted

Paul Reed

unread,
Jan 5, 2018, 2:40:40 PM1/5/18
to Node-RED
INSERT INTO `MyDatabase` (`KWh1`,`KWh2`,`KWh3`) VALUES (" + Energy1 + "," + Energy2 + "," + Energy3 + ")

Paul

Folke Haglund

unread,
Jan 5, 2018, 2:55:11 PM1/5/18
to Node-RED
I have tried that, but it does not work.
// Folke

Paul Reed

unread,
Jan 5, 2018, 3:03:13 PM1/5/18
to Node-RED
Just saying it doesn't work, is not really helpful!
What have you tried, are there any error messages/log entries, have you set up your MYSQL credentials correctly, what does the relevant part of your flow look like ?

Paul

steve rickus

unread,
Jan 6, 2018, 11:04:52 AM1/6/18
to Node-RED
If I recall correctly, that insert statement needs to be in msg.topic, not msg.payload... the output payload then returns the matching results.

Folke Haglund

unread,
Jan 6, 2018, 11:13:27 AM1/6/18
to Node-RED
I have a solution and it looks like this.

msg.topic = "INSERT INTO table (Id, Time, KWh1, KWh2, KWh3, Totalt) VALUES (id, CURTIME(), " + CurrentEnergi1 + ", " + CurrentEnergi2 + ", " + CurrentEnergi3 + ", " + TotalEnergi +")";

//Folke

Cristiano Nunes

unread,
Jan 7, 2018, 9:41:34 PM1/7/18
to Node-RED
var sql = [];
var outputs = [];

sql = "INSERT INTO table (Id, Time, KWh1, KWh2, KWh3, Totalt) VALUES (id, CURTIME(), " + CurrentEnergi1 + ", " + CurrentEnergi2 + ", " + CurrentEnergi3 + ", " + TotalEnergi +")";

outputs.push({topic:sql}); 

return [outputs];



hello, try this code.

Folke Haglund

unread,
Jan 8, 2018, 3:16:04 AM1/8/18
to Node-RED
It works too.
Thank you.
//Folke
Reply all
Reply to author
Forward
0 new messages