Node-Red: Zbieranie informacji na temat temperatury za pomocą narzędzia Node-Red

Jeżeli chcesz przeczytać jak działa Node-Red kliknij tutaj.

Przepływ node-red.

konfiguracja HTTP request

Kod w środku węzła 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;