Node – RED

Node RED is powerful, extensible, graphical programming environment. It’s a flow based modelling tool which make it easy to create event-driven applications in a simple & intuitive ways.

Its built on top of NodeJS and provides a browser based editor for wiring flows together. Node RED development environment is actually a web page running on your pi or it can run in cloud environments making it vary versatile tool.

It is used in scenarios spanning a wide range of industries from manufacturing and utilities, healthcare and agriculture, home and industrial automations.

Originally developed as an open source project at IBM in late 2013, to meet their need to quickly connect hardware and devices to web services and other software – as a sort of glue for the IoT – it has quickly evolved to be a general purpose IoT programming tool. Importantly, Node-RED has rapidly developed a significant and growing user base and an active developer community who are contributing new nodes that allow programmers to reuse Node-RED code for a wide variety of tasks.

The official website provides a great collection of resources for getting started with Node-Red. They also have video tutorials and other documentation and I will recommend to go through those to have a better understanding of this exciting platform. You can find the link in reference section of this post.

Node-Red is pre-installed in Raspberry Pi installations or you can run it on your local machine easily via docker.

Running under Docker

>> docker run -it -p 1880:1880 –name mynodered nodered/node-red

Here is the running container

Thats all you need to run it locally via docker. Once the container is running, you can just browse the url http://localhost:1880 via web-browser and you will see the IDE as follows. Simple, right?

Node-RED Editor Components

  • Palette
    • List of all nodes you can use to create flows. These are separated in categories to keep them organized.
  • Workspace
    • This is where you create your workflows.
  • Header
    • Deploy button is what you click to take your current flow configuration and send it to node-RED run-time.
  • Menu
    • Many useful features
  • Side-Bar
    • Number of Tabs with different tools.
    • Info Tab, Debug Tab (show messages passed to debug node),Config Tab

Create a Flow

Process of creating a flow involves adding Nodes to the workspace and wiring them together.

Create a Simple Flow

  • Drag inject node from palette to workspace. Inject-Node allows you to manually inject messages to flow.
  • Add a debug node.
  • Wire inject-node and debug-node together by clicking the output from inject-node to input of debug-node.
  • Now, whenever inject-node send a message, it will be received by debug-node.
  • Click Deploy button to push it to run-time. Once deployed, click the button next to inject-node & check debug-window for messages.

Function Node

  • Function-Node allow you to write JavaScript which will be executed for every message.
  • Add a function-node (toISOFormat) between inject & debug node, write javascript as shown in pic below.
  • Deploy, and Check the debug messages.

Here is the JavaScript code.

Once, deploy notice the change in debug messages.

Node-RED with Twitter API

You can do interesting thing with Node-RED platform, e.g. I experimented working with twitter API.

I created the flow, which monitor twitter API for particular Hash-tags (in my case i used #Hitachi, but you can monitor whatever you like).

So, whenever some one use this tag, my NODE-Red flow will get notification and information about the tweet (so this part is about reading from twitter).

I also added the write functionality, in my case, Node-RED will create a tweet and post on twitter.

Please find below, screenshots of that flow. Its a quite simple example and you will find similar flows on Node-RED website as well. The point is, that I was able to setup all this very easily without having extensive underlying Twitter API knowledge.

Here is the tweet, I used the #Hitachi tag:

Here is the basic flow to get the tweets for particular hash-tag.

Here is the debug information showing the tweet.

Saving Tweets to a File

This is just a small update of previous flow, so I use another built-in Node to write to File

Creating Tweet

In this update, Node-Red allows me to create tweet easily. So whenever it receives a Tweet, it can automatically create a reply and post it to twitter.

Here is the Tweet-Reply screenshot

Summary

So, we saw the basic components of Node-RED, you can create very interesting flows. For the twitter API example above, you will need developer account from Twitter and API keys to use in your Node-RED flow.

I will also suggest to check my other articles about MQTT and IoT, to have better understanding of this and upcoming posts.

In my next blog posts, I will bring in MQTT and some Raspberyy PI or arduino to see how all of these worked together. Till next time, Happy Coding.

References


Discover more from Hex Quote

Subscribe to get the latest posts sent to your email.

Discover more from Hex Quote

Subscribe now to keep reading and get access to the full archive.

Continue reading