Node-RED: Requesting sensor data via HTTP

(Last Updated On: )

Fo as cool and useful as Node-RED is I am surprised at the lack of “useful” documentation and examples on the web. Sure has some very useful flows and nodes, no doubt but they don’t really help a beginner slap some IoT goodness together. I have some knowledge but I by all means don’t have “skills”, at least I don’t think so. Anyway enough rambling on to the code…

Screen Shot 2015-11-17 at 10.36.29 PM

DISCLAIMER: I by no means really know what I am doing, I know just enough to be dangerous. I am not responsible for what you do or what happens, by you or someone following anything mentioned on this page (or site).


Display sensor data on a webpage with Node-RED
This should allow you to take data from a sensor or another node and display it on a webpage.

Nodes you will need:

  • HTTP request (set as GET)
  • Function (Get current values)
  • Template (HTTP)
  • HTTP Response

Get Current Values Function

HTTP Template

That is the bulk of it, now all you have to do is declare the global variables you just created. Add a function block directly after your sensor (or edit the one you already have). Now you just need to set the sensors payload to equal the global variable.

Set each global variable for each sensor you have like this (I added it at the very bottom, before “return msg;”.): = msg.payload;

Refresh the page button

This should allow you to get a button on a webpage to refresh the page for you.

Nodes you will need:

  • HTTP request (set as GET)
  • Function (Return to page)

Return to page Function:

Well thats it, I hope this was enough straight forward code and enough direction to get you going. I had to scrape this all together. One is glad to be of service.

For your pleasure and in the chances I may help cure some headaches, because I hate headaches, here is all the code (minus setting the global variables):

This post is were I found the code needed to get the above results:!searchin/node-red/gpio/node-red/ycho_15kJvM/bTOY9tbwrmYJ

Discover more from Its_All.Lost

Subscribe to get the latest posts to your email.

Leave a Reply