Hacking the world around you to bend it to your will is getting easier and easier.

Whether it’s setting up a lamp to flash when someone retweets you or a system to text you when the washing’s done, work is taking place to make it simpler for machine to speak unto machine.

Hooking up the wealth of computers, sensors and online services in the modern world can lead to weird and wonderful creations, for example this whistle-controlled drone.

But the nitty gritty of working with this internet of things is a tad repetitive. To take away some of that drudgery researchers at IBM hit on the idea of building a toolbox of reusable code that people could use to more easily wire together software and devices into useful systems.

IBM researchers were looking for a way to simplify the process of hooking together systems and sensors when building proof-of-concept technologies for customers.

“We were chatting and Nick said ‘There must be an easier way of doing this’,” said Dave Conway-Jones, senior inventor at IBM.

Conway-Jones is referring to Nick O’Leary, emerging technology specialist at IBM, who at the time had been experimenting with using drag-and-drop graphical tools to build the code needed to let web services, software and hardware communicate. It is these tools that would develop into Node-RED.

Node-RED is an event-processing engine that basically prevents hardware and software hackers from having to continually reinvent the wheel. O’Leary uses the example of having to write code to send data to a device via its serial port every time they started a new project.

“Dave and I know how to write code to talk to a serial port but it might take a little while to remember how to do it and get it written.”

“To talk to a serial port using Node-RED it’s just a case of dragging on a node and giving it the serial port details and you’re done. It gives us this agility to rapidly prototype.”

Node-RED doesn’t take away the need to write code altogether, but it does reduce it, and in the process both lowers the technical bar and allows people to focus on the creating, rather than on the doing.

“Just as a spreadsheet lets you to play around with numbers, Node-RED is a tool that’s good for playing around with events,” said Conway-Jones.

“People who aren’t programmers can start thinking ‘I’ve got Twitter here and I want to analyse what’s being said and publish it into a document over here, how can I do that?’. For instance you could have a Twitter feed coming in, do a bit of sentiment analysis on the tweets and send all the good ones to an email address.

“People working at almost business level functions, not quite but getting to that level, could do this. That’s that level we want to get to.”

What is Node-RED?

At first glance the interface for Node-RED may remind users of Scratch, the MIT-developed graphical tool that allows children to code simple programs by dragging and dropping software commands.

Like Scratch, Node-RED provides a GUI where users drag-and-drop blocks that represent components of a larger system, in Node-RED’s case usually the devices, software platforms and web services that are to be connected. Further blocks can be placed in between these components to represent software functions that wrangle and transform the data in transit.

Perhaps the best way to understand what Node-RED is is to see it. Below is Node-RED’s representation of a “Hello World” program, commonly used to introduce someone to a new technology or programming language. For those unfamiliar this program is usually a very simple routine that prints the message ‘Hello World’ on the screen.

Here you can see Node-RED’s graphical user interface and how the platform breaks systems down into their constituent parts.

Each of the rounded blocks you can see on the screen is a node, which is a visual representation of a block of JavaScript code designed to carry out a specific task.

To build the ‘Hello World’ program the user drags into the central window an ‘inject node’, a node designed to output a message to other nodes.

This inject node is edited to output the string ‘Hello’.

Next a function node is dragged on and edited to define a JavaScript function that appends the string ‘ World’ to any message it receives.

These two nodes are then wired together. Most nodes have a grey circle on their left edge, which represents their input port, and on their right edge, which represents their output port. Left clicking and dragging the output port of the ‘Hello’ node to the input port of the ‘ World’ node connects the two together.

The final stage is to add a Debug node that prints the message it receives in the Debug window. This Debug node is then wired to the output of the ‘ World’ node.

The process is now ready to run and once deployed will display the string ‘Hello World’ in the Debug box, shown on the right of the screen.

This finished program is an example of what is called a flow in Node-RED.

What’s interesting about Node-RED is it can do much more than spit out a simple message, it can also glue together web services and hardware, and that’s where it starts getting powerful.

Take this use of Node-RED by photographer and IBM employee Dom Bramley, who captures images of the night sky. The equipment he relies upon isn’t waterproof but needs to be left outside overnight to photograph the stars.

He used Node-RED to build a personal weather alert system, which works by controlling the lights in his home. Bramley built a flow that connected to the forecast.io weather API every three minutes to check local rainfall predictions. A second node took the response from forecast.io and used it to calculate how many minutes until rainfall would arrive at his home. An ambient lamp in his living room then shifted colour based on the number of minutes until rainfall arrived, while a bedside lamp switched on if the rainfall was close enough to be deemed unsafe.

Two flows controlled the lights in the house, one created an RGB value that changed the colour of an ambient light based on the proximity of the rain. The second sent a signal to an MQTT-connected Arduino controlling a 433MHz plug socket, which turned on a bedside lamp if an unsafe condition was triggered.

Node-RED was the glue that held the weather alert system together, allowing Bramley to suck data from forecast.io API, to extract a useful insight from it and use that information to manipulate automated systems in his home.

Building the internet of things

Bramley’s weather alert flow demonstrates how Node-RED lets creators build on work of others.

For instance, to pull data from forecast.io Bramley imported an existing node that submits HTTP GET requests. All he had to do was edit the URL that the request is made to and add a string that set his query.

In turn Bramley’s weather alert system is available for others to import into Node-RED so they can use and abuse it as they see fit. Even if they didn’t want the whole flow they could just cannibalise it for parts, perhaps just installing the node for changing the colour of the ambient lighting system.

“In Node-RED you can wrap up any bit of functionality, encapsulate that function as a node in our palette,” said O’Leary – listing modules for an MQTT client and talking to serial ports on hardware as examples of functionality incorporated into nodes.

“This palette of nodes isn’t hardcoded so you can just drop in new nodes and when you start you have new functionality.

“It’s that ecosystem of nodes that makes Node-RED a platform that people can contribute back to.

“It means we don’t have to spend time worrying on how to handle specific technical challenges. We can focus on what do we want this application to do. You get to focus on the what, rather than the how.”

New nodes for interacting with hardware, software and web services are being added all the time. Recent additions include nodes for controlling Belkin WeMo remote-controlled sockets and Philips hue lighting. Nodes can also be written to take advantage of software platforms, with nodes to send SMS messages via Twilio and messages via Twitter.

The technical bar for writing a node isn’t especially high, as a node is simply an encapsulation of some JavaScript code running in the node.js environment.

There is already an active community regularly producing new nodes and the Node-RED platform is an open-source project hosted on GitHub, so anyone is able to contribute.

Node-RED flows are represented in JavaScript Object Notation or JSON and can be easily exported to the clipboard to be imported into Node-RED or shared online.

IBM is also considering making it simpler to build on the work of others in Node-RED by introducing sub-flows. Sub-flows would allow users to collapse flows of multiple linked nodes into a single node, allowing more complex logic to be abstracted into a single node.

The many faces of Node-RED

“Everyone comes at it with a completely different perception as to what Node-RED is or what it could be,” said O’Leary, referencing how the flexibility of the platform has led to people seeing possibilities that weren’t originally envisioned.

“Clearly it’s a platform that has many different applications, different sectors see different things in it.

“We’re building a platform that anyone can contribute nodes to so it solves some problem for them, and then contribute those nodes back in.”

For example education wasn’t the focus for IBM when designing Node-RED, but the drag and drop simplicity of building programs in Node-RED has led to some schools looking into using it as a platform for teaching children about coding and hardware hacking.

And O’Leary said that over time more nodes may be added that abstract away more of the coding, to make Node-RED less daunting to people without knowledge of programming.

“There’s definitely a space for more higher level abstraction,” he said.

Lowering the technical bar is made simpler by how easily Node-RED can be extended, for instance by adding nodes to carry out common programming constructs, such as a For loop.

O’Leary talked also about the possibility of someone creating Node-RED flows to embody lessons for teaching children about electronics and computing, so a teacher could switch a Raspberry Pi connected to sensors to be run in “lesson number one” mode.

Node-RED is currently popular for running home automation, according to O’Leary, citing cases where it has swept aside “the mess of Perl and Python scripts” previously holding these systems together, he said.

Just how a good a fit Node-RED is for home automation becomes obvious when you step into IBM’s Emerging Technologies lab in Hursley, England. Researchers have used Node-RED to allow the same wireless switch to turn on a fan, alter the display on an LED sign or flick a lamp on and off. Changing what the switch does requires nothing more than clicking on the Node-RED flow and changing the wiring between nodes, a task that takes seconds to accomplish.

Even more exotic uses have been found for Node-RED at Hursley. A flow has been written to control a drone by whistling, a rising tone makes the drone take-off and descending tone makes it land.

Node-RED is already helping IBM glue together proof of concept demonstrations for customers. The firm recently ran Node-RED flows on Raspberry Pi boards to connect Arduino boards to webcams and temperature, pressure and humidity sensors monitoring a factory production line.

“Of course we could have written code to capture all of that but it would have been much less flexible, because when you add new sensors you have to go in and work out where to add new bits of code,” said O’Leary.

When the same firm had a problem with builders unplugging the server gathering this data – so they could plug in their power tools – IBM were able to, “in the space of about five minutes”, use Node-RED to wire together a system that automatically emailed key personnel if the server went down.

“For us the flexibility is the value,” said O’Leary, “but other people see different value.”

For businesses that value could be sorting data near to where its collected on the edge of the network, filtering out the noise and only sending back relevant information.

“What we’ve got here is something that allows you to push logic and business control to the edge of the network, right down to a Raspberry Pi or a little embedded Linux box,” said O’Leary.

“That’s an interesting area. It’s suited to running at the edge of the network because of its light footprint. It can monitor events locally and only send something up to the enterprise when you need to, rather than having to send all you data up your central data enterprise hub and deal with it there.”

Limitations of Node-RED

Node-RED is an application based on node.js, a server side JavaScript platform that uses an event-driven, non-blocking I/O model suited to creating data-intensive, real-time applications that run across distributed devices.

For a device or a service to work with Node-RED there needs to be a node.js library or module capable of talking to them.

But the number of compatible services and devices is extensive, thanks in part to a tendency for many modern platforms to expose their data and functional via open APIs that accept HTTP requests.

And because Node-RED runs on node.js it can also happily run on a range of less powerful devices, such as the $35 Raspberry Pi.

What’s next for Node-RED?

IBM open-sourced the Node-RED platform in September and O’Leary said IBM has “a whiteboard full of plans, ideas and features to slowly work our way through”.

Node-RED is an evolving platform that O’Leary expects will find new audiences as the community build new tools on top of it.

“This still isn’t something that my mum would use, but there are certainly plenty of people that this is enabling to do more than they thought they could.”