Your shopping cart is empty!
IRIV PiControl - Node-RED IoT - Monitor Data using Thingspeak And HTTP Requests
- Abdulrahman Alhamed
- 24 Mar 2024
- Tutorial
- Advanced
- 632
Hi and welcome back to another tutorial on using IRIV PiControl and Node-RED. Today, we'll learn how to use HTTP Requests to monitor data on Thingspeak.
What is HTTP Requests?
HTTP (Hypertext Transfer Protocol) requests are messages sent by a client (like a web browser) to a server to initiate communication and request resources, such as web pages, images, or data. These requests contain information about the desired action (e.g., GET for retrieving data, POST for submitting data), the URL of the resource, headers for additional information, and sometimes a body with data. The server processes the request and responds with an HTTP response, which may include the requested resource or an error message.
How does it work?
Before we send large data to Thingspeak using HTTP Requests, let’s understand first how does that work in Node-RED.
Basically, we will need 2 function nodes, the first one will be used to store data in it, and the second function node will send these data to Thingspeak via HTTP request node.
In this example, I’m using an inject node to send number 5.
Then we will open the first function node to store number 5 in it. All you have to do is create a new variable by typing (context.flow.test1), then make that variable equal to the msg.payload that is coming from an inject node.
Now open the second function node so we can adjust it and send data to Thingspeak.
Start by defining the method as “GET”.
Then type in the url link.
You can get the link from Thingspeak, under the API Keys section.
Copy and paste this link to your code, then delete the number zero from field1, and after that, write in the variable name that is storing our data.
Now open, the HTTP Request node, and change the method to (set by msg.method).
Before we test out the program, make sure you’re already set up your channel and activating field number 1.
Press Deploy and hit the inject node.
Now, you will notice that data has been sent to Thingspeak cloud and can you view it from there.
Monitor Sensor Data on Thingspeak
Now let’s see how we can monitor real-time sensor data on Thingspeak.
In this example, I’m using these nodes to store the data that are coming from the RS485-Industrial-Temperature-and Humidity-sensor.
Inside the Humidity function, I’ve created a variable called (context.flow.humidity) to store humidity readings from the sensor.
And I did the same for the Temperature sensor.
To learn more about how these nodes work together, please see this tutorial.
Next, I’ve created these nodes to store the data that are coming from the Power Meter, each function node, has a unique variable to store specific data.
For example, the first function node is storing Voltage readings, the 2nd function node is storing Current readings, and the 3rd function node is storing Power readings.
To learn more about how these nodes work together, please see this tutorial.
Next, I used a function node to send data to Thingspeak.
You will notice here I’m using 5 fields, each getting data from a certain variable, the ones we have created before.
And I also, have enabled these fields in the channel settings, in Thingspeak. So make sure to do so as well.
Lastly, I’ve used an HTTP request node, and adjusted its method to (set by msg.method)
Next, I will connect the nodes together this way, and I will hit Deploy.
Now, once we open Thingspeak, you will notice the data are displayed in these line charts.
That’s all for this tutorial, thanks for reading, and stay tuned for more.