Wire IoT Up To IBM i With Node-RED
July 6, 2020 Alex Woodie
The Internet of Things (IoT) brings a new way to think about our digital world. From sensors on a manufacturing line to Twitter messages from the other side of the world, the IoT brings it all together. And with Node-RED, a low-code framework that is available on IBM i, wiring up these data flows into useful applications is surprisingly easy.
Created by IBM, Node-RED is a Node.JS-based framework for developing event-driven data applications, or “flows,” that deliver a data payload in the form of the JavaScript Object Notation (JSON) data standard, from a source to a destination. Node-RED flows are assembled in a Web browser in a drag-and-drop manner using a variety of pre-built data inputs and outputs, or “nodes.” With a few more clicks, the apps are deployed into a Node.JS runtime, including on IBM i.
The availability of a wide range of pre-built and open source nodes is part of what makes IoT application development so fast on Node-RED. Among the 2,200 nodes available are ones for specific hardware devices, such a Siemens programmable logic controller (PLC) or the Slack API. A node has been available for Db2 for i since 2017, enabling Node-RED developers to tap into the richness of SQL on the IBM i platform.
There’s a wide range of possible applications that can be developed on Node-RED. A developer could string together input from a Twitter node, wire it up to an IBM Watson sentiment analysis algorithm, and then have an email automatically generated to inform her sales team when unhappy customers are ranting on social media. It can be used to help with password resets in a help desk setting; to populate dashboards with real-time information of energy generation; to warn a system administrator when DASD capacity on the IBM i server reaches 90 percent capacity; to give a trucking company CEO where his fleet is; or to stream video of unruly mobs converging in city streets to a precinct captain.
One of Node-RED’s biggest fans on IBM i is (not surprisingly) is Jesse Gorzinski. IBM’s business architect for open source recently recorded a presentation on Node-RED for COMMON’s iNSIGHT virtual event, where he delved into the framework, discussed how it works, and provided examples of real-world Node-RED deployments, and explored some possibilities for others to try.
“If you think about a lot of the software development that happens today, it’s really about connecting pieces, connecting things,” Gorzinksi said. “Maybe you want a Slack message connected to some sensor device. Maybe you want an API connected to the database. Maybe you want some social media post connected to some user action on a web form.”
It’s not that hard to build these sorts of applications, particularly in Node.JS, which is an increasingly rich developer ecosystem with many open source samples to choose from. According to Gorzinksi, there are more than 1 million Node.JS modules available in NPM, the Node.js Package Manager that is used to publish and install Node.JS code and applications.
“But what we found was a lot of people are still spending time doing non-valued added activities,” he continued. “With Node-RED, it’s really easy to develop these things without worrying so much about the inertia and the implementation behind talking to all of these various things.”
Node-RED’s biggest benefit is that it brings a simple low-code approach to developing IoT applications, Gorzinski says. However, it’s important to note that Node-RED is not a “no-code” environment. Users will be expected to exercise their JavaScript skills to create custom business logic for their Node-RED data flows.
“You still are going to write some JavaScript code,” he said. “But you’re going to write a lot less than if you were to open a blank JavaScript file and start coding away.”
Most of the development process for Node-RED involves dragging and dropping various nodes onto the palette, which defines the data flow. Developers have a range of node types to choose from. Those common types are input and output nodes, which define the beginning and end (or ends) of the data flows. Additionally, there are a host of other function nodes for other operations.
There are many pre-built nodes that developers can use available from the www.npmjs.com website, including custom nodes from industrial firms like Siemens and Hitachi and nodes that capture data from various applications. There are nodes for grabbing data off Raspberry Pi devices; for generating speedometers and other graphical elements for dashboards; for Amazon Alexa; and even for reading data from RFID chips.
If a developer makes an error in configuring her nodes and flows, the Node-RED development environment will flash a red triangle to let her know something is not quite right. Developers can get documentation for a node by simplifying hovering her mouse of the node. Deployment is handled by the click of a button, and there are options for deploying only changed portions of a palette or the whole thing (as a single palette may contain multiple flows). Since all the data is stored as a big JSON document, exporting these flows is as simple as copying and pasting text into a JSON file.
One of the cooler use cases for Node-RED shared by Gorzinski was configuring an AI chatbot to help with password resets. This application, which the IBM France team created in just two hours, utilized Watson’s natural language processing (NLP) capability to determine the concern that users presented in a Slack channel. “It’s able to ameliorate and fix a lot of common problems. That’s able to free up the human helpdesk workers to do more productive things,” he said.
Node-RED may not be widely used on IBM i, but it’s starting to gain some traction. According to Gorzinski, the Db2 for IBM i node has been downloaded from the NPM over 7,000 times since it became available in 2017. Several vendors are beginning to use it in their applications, too.
Open source has been a boon for productivity on IBM i, and provided IBM i developers with the abundance of creativity and capability that developers on other platforms are enjoying. With Node-RED, IBM i developers can take their creations to new heights by wiring them up to participate in the broad IoT ecosystem. That makes it worth checking out, according to Gorzinski.
“When I was first introduced to Node-RED and this concept, I thought, well this seems really simple,” he said. “This does not seem too powerful to me. How much can you really do manipulating JSON and passing it down a flow?
“But the answer is actually quite a lot, because all the work is actually done inside those nodes,” he continued. “And again, what Node-RED is allowing me to do as Node.js programmer is focus on the solution rather than focusing on wiring together the code to make all of this happen.”
RELATED STORIES
More Open Source Databases Coming To IBM i
What’s New In Open Source With The Latest TRs
Open Source Is the Future, So Where Does IBM i Fit In?