Using HTTP with Node-RED#
We are going to show you how to send HTTP data to your Node-RED server
Requirements
A Raspberry Pi (or other device) with Node-RED installed
A device that communicates via HTTP (we used an Arduino UNO R4)
Guide#
We will set up Node-RED to receive data. First add a http in in node onto the flow
The Arduino code in An example can be found here is set up to send a http POST request.
So, we therefore need to configure your Node-RED HTTP method to POST:
You then will need to add a function to the HTTP Post to read the message:
// Assuming msg.payload is in the format received from Arduino
// Extracting temperature and humidity
var devicename = msg.payload["deviceName"]
var voc = msg.payload["tvoc"];
var co2 = msg.payload["co2_eq"];
// Prepare SQL query
var timestampISO = new Date().toISOString();
var timestamp = timestampISO.replace("T", " ").split(".")[0];
var theSQL = "INSERT INTO voc_co2 (timestamp, deviceName, voc, co2) VALUES ";
theSQL += "('" + timestamp + "','" + devicename + "', " + voc + ", " + co2 + ");";
msg.topic = theSQL;
return msg;
After decoding the message from the Arduino, we then need to store the values in the database we created in An example can be found here.
Sending the message is achieved using the sqlite node:
Verifying the data is being stored correctly#
Access your Node-RED using ssh, as described here: An example can be found here.
Then inspect your database using sql: