Node-RED is a visual tool for wiring together hardware devices, APIs and online services – for wiring the Internet of Things.

Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click. JavaScript functions can be created within the editor using the a rich text editor. A built-in library allows you to save useful functions, templates or flows for re-use.

The light-weight runtime is built on Node.js, taking full advantage of its event-driven, non-blocking model. This makes it ideal to run at the edge of the network on low-cost hardware such as the Raspberry Pi as well as in the cloud.

1 Install node red on Raspberry Pi

As of the November 2015 version of Raspbian Jessie, Node-RED comes preinstalled on the SD card image that can be downloaded from

If you have an older version, you can install it doing:

sudo apt-get update
sudo apt-get install nodered

2 Running node red

To start Node-RED, you can either:

  • on the Desktop, select Menu -> Programming -> Node-RED.
  • or run node-red-start in a new terminal window.

To stop Node-RED, run the command node-red-stop.

3 Connect to Watson IoT platform using Node-RED

In the following example we will publish Raspberry Pi CPU temperature to the Watson IoT cloud Platform using Node-RED

  1. Let's check the Raspberry Pi board temperature
    $ vcgencmd measure_temp
  2. Now start nodered on Raspberry
    $ node-red-start
  3. Connect to nodered using a web browser. You can see nodered console.
  4. From input, add inject block (timestamp)
  5. From advanced, add exec block that will get CPU temp and fill in the exec node data as follows
  6. Wire timestamp output to getCPUtemp input
  7. From output, add a debug block and wire getCPUTemp output to debug input
  8. Deploy the changes, and select debug tab
  9. Click on timestamp left checkbox to inject an event. You should see the temperature on debug window foreach click like
    9/4/2016, 1:23:40 AMc708accf.a751c
    msg.payload : string [12]
  10. Add a function to trasform output from getCPUTemp to a format appropriate for Watson IoT.
  11. Transform the temperature to the format required for Watson IoT using a function
    msg.payload = {'d' : {'temp': msg.payload.replace("temp=","").replace("'C\n","")}}
    return msg;
  12. Wire the output of getCPUTemp to the input of the function.
  13. Wire the output of the function to the debug input.
  14. Deploy the changes, and send a new timestamp.
  15. You should see function output like
    { "d": { "temp": "50.5" } }
  16. Change timestamp to repeat automatically every 3 seconds.
  17. From output, select a Watson IoT block and wire the function output to Watson input.
  18. Deploy the changes, so time event forces data collection every 3 seconds.
  19. Now, open watson IoT block and click on Quickstart Id right link.
  20. You can see real time CPU temperature is beeing send from your Raspberry Pi box to IBM Watson Cloud plaform.