To log data in MS SQL Server Table using Node-RED, you can follow these steps:
Install the node-red-contrib-mssql-plus module in your Node-RED instance. This module provides nodes for interacting with MS SQL Server databases.
Create a new MS SQL Server database table where you want to log your data.
Add an mssql node to your Node-RED flow, and configure it with the appropriate database connection details.
Add a function node to your flow, and write the code to prepare and insert data into the database table. Here's an example code:
javascriptCopy code
var timestamp = new Date().toISOString();
var value1 = msg.payload.value1;
var value2 = msg.payload.value2;
var sql = "INSERT INTO mytable (timestamp, value1, value2) VALUES ('" + timestamp + "', " + value1 + ", " + value2 + ")";
msg.topic = sql;
return msg;
This code takes the current timestamp, as well as two values from the msg.payload object, and inserts them into the mytable table. You can customize the code to match your own table schema and data types.
Connect the function node to the mssql node, and deploy your flow.
Now, whenever your flow receives new data, it will be logged to the MS SQL Server table.
Keep Testing ! Keep Learning !