Search code examples
http-posthtmlibm-cloudarduino-unonode-red

How to create simple Node Red Web Page to display "HTTP In" node data from my device


I can successfully push my JSON formatted sensor data using HTTP Post out of my Arduino Uno/AdaFruit CC3000 Wifi Shield into Bluemix and see it on my Node Red debug console using the "HTTP In" and "Debug node". Works perfectly! (Had to use HTTP Post since I am out of memory on the Arduino Uno and HTTP POST was the leanest way to move the data.)

MY QUESTION: within node red, how to take the output of that "HTTP In" node and put it on a web page served from Bluemix that displays the last five sets of sensor data pushed out every five minutes. The web page should not need to be manually refreshed by a visitor to the page.


Solution

  • There are many possible ways to do this depending on how you want to store the history of sensor readings or server up the basic html file. I'll outline the idea for just keeping values in memory.

    Basically the simplest way is to enable static file serving (see Node-RED doc here) and serve up a basic html file with some javascript that can connect to a websocket.

    Your original http-in (POST) should then be connected to a function node which will push the values to the global context and then a http-out to close out the POST properly. You then want to branch this flow to a websocket-out (Listen) node that javascript in the web page can connect to in order to get the latest values pushed into the page in realtime.

    The static page can then use another http-in(GET) node with another function node (or template node) to read the pervious values out of the context lined to a corresponding http-out node.

    That should be enough to get you looking in the right direction