S7-1200 to MariaDB

Hello there! I am using node-red-contrib-s7 v.3.1 and node-red-node-mysql v.1.0.3 to read data from a PLC and perform a INSERT on a MARIADB Database. Right now I can both read from the PLC and perform INSERT on the DB using separately but when I try put those two together I struggle with the syntax.

FYI the datatype or the variable is REAL and I have a 'S7 Input' Node feeding a 'Function' node


var LeftSide_Dist = msg.payload;

LeftSide_Dist = LeftSide_Dist.toString();
var topic = "INSERT INTO myDB.stack (LeftSide_Dist, RightSide_Dist, LeftSide_Shift, RightSide_Shift, Top_Angle, Bottom_Angle, Code, `timestamp`) VALUES("+"LeftSide_Dist"+", 2, 3, 4, 5, 6, 7, current_timestamp())";

msg.topic = topic; 
return msg;

Can someone help me out?

Yay, I got the syntax right! I just had to lose the double quotes because it was a variable, kinda obvious...

var LeftSide_Dist = msg.payload;

LeftSide_Dist = LeftSide_Dist.toString();

var topic = "INSERT INTO myDB.stack (LeftSide_Dist, RightSide_Dist, LeftSide_Shift, RightSide_Shift, Top_Angle, Bottom_Angle, LensCode, `timestamp`) VALUES("+LeftSide_Dist+", 2, 3, 4, 5, 6, 7, current_timestamp())";

msg.topic = topic;

return msg;

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