Node-Red: Collecting temperature information with the Node-Red tool

If you would like to read how Node-Red works click here.

The flow of node-red.

HTTP request configuration

Code inside the node Make Query

// Format current date-time as a string
const now = new Date();
const dateStr = now.toISOString(); // You can reformat if needed
 
// Get the temperature from the payload
const temp = msg.payload;
 
// Extract the numeric value from the temperature string
const tempValue = parseInt(temp.replace(/[^\-?\d]/g, ''));
msg.temp = tempValue;
// Construct the SQL query (excluding ID)
msg.topic = `
    INSERT INTO WarsawTemp ([DATE], [TEMP]) 
    VALUES ('${dateStr}', ${tempValue})
`;
 
return msg;