Using Node-RED & MQTT with PLCnext Technology

Learn how Node-RED & MQTT integrate with PLCnext Technology for IIoT applications.
Node-RED MQTT PLCnext - thumbnail
Listen to this article

In this article, we’ll introduce you to the future of manufacturing made possible by the Industrial Internet of Things, or IIoT, and explore some of the tools that will work with and alongside it.

Ok…here we go…

What is IoT?

Unless you’ve been living under a rock, you’ve probably heard about the Internet of Things or IoT already. The IoT is not new. The IoT has been around for many years, but the term was not made popular until the early 2000s.

The first emerging IoT devices were consumer devices such as home thermostats and security systems.

IoT Vs. IIoT

So, what’s the difference between the IoT and the IIoT? Well, not that much, as the terms are often used interchangeably. The big difference is their applications. IoT devices are consumer-focused, while IIoT devices are industry-focused.

The IoT refers to a network of physical devices or things embedded with sensors, software, and other technologies to connect and exchange data with other devices and systems over the internet.

The IIoT is technically part of the IoT but specifically targets industrial applications. It connects machines, sensors, and systems using more robust and secure technologies to improve operational efficiency, safety, and reliability.

Ok…so how do we connect to the internet using our IIoT devices, and how do we collect and act on the data we get from these devices?

Node-RED

Let’s go back a few years and introduce you to Node-RED. Node-RED is a visual programming tool developed by IBM for IoT and designed to connect devices and online services.

Node-RED is a star player in the IoT world, facilitating the connection and automation of IoT devices.

What’s great about Node-RED is that it’s open-source and free for anybody to use.

It can be run on many cloud services, such as AWS, Microsoft Azure, and IBM Cloud.

With its visual interface, you can quickly build robust applications to automate and monitor your processes.

The Node-RED community has grown substantially, and numerous plugins have been developed to extend its functionality. The Node-RED library includes thousands of community-contributed nodes, continually expanding integration with increasing devices and services.

What does Node-RED look like on your computer screen?

In Node-RED, users create flows by connecting nodes on a worksheet representing functions or devices, forming a visual representation of the workflow.

Node-RED comes loaded with many standard default nodes for your use.

Node-RED standard default nodes

Other nodes that interface with a PLC program can be added and consequently collect data from field devices.

For example, nodes can be added to interface with PLCnext Technology.

Alright…so we’re using Node-RED to collect data from field devices connected to a PLC. This data can be anything from the temperature of a commercial cookie oven to the flow rate through a pipe. How can we move this data via the Internet or a cloud-based database?

MQTT

A very popular messaging protocol is Message Queuing Telemetry Transport, or MQTT. Its inherent characteristics make it ideal for IoT devices.

MQTT has two primary entities: the broker and the clients. The broker acts as a central hub directing communication between clients. Clients can be devices or applications that send or receive messages. MQTT operates on a publish/subscribe model.

An MQTT message consists of a topic and a payload. The payload carries the actual data, while the topic categorizes the message and determines which clients will receive it.

MQTT requires the use of a central Broker.

MQTT Brokers are available on the internet, including Mosquitto, HiveMQ, CloudMQTT, and many more.

Node-RED and MQTT integration

So, if we combine Node-RED with MQTT, we get a dynamic team for IIoT solutions. We can set up a system in which sensors, controllers, and monitoring tools all communicate seamlessly.

Let’s look at an example of using Node-RED and MQTT together. We will use Node-RED to collect the data and MQTT to move it. In our example, we’re using PLCnext Technology.

We use the plc-read-variables node to read three variables: Slider, TEMP, and ALARM.

We’re using an MQTT out node to collect the variable data from the plc-read-variables node and an MQTT in node to receive the data from the broker.

As we discussed, MQTT uses the Publish/Subscribe model to send and receive messages between clients. We are using Node-RED MQTT nodes to publish and subscribe to messages.

MQTT publishes and subscribes to Topics. We have created a Publish Topic called Temperature. The message in our publish topic contains the three variables originating from the Node-RED plc-read-variables node.

We have a PC subscriber also subscribed to the topic Temperature. Whenever the Temperature topic values are published, the Subscriber PC will receive the message containing the three variables.

We use Mosquitto MQTT as the Broker.

The broker receives and filters all messages, subsequently publishing them to the PC, which is the subscriber.

We use the MQTT Broker via our PLCnext Controller.

MQTT messages are an event-driven paradigm, where they are sent and received in response to specific events.

In our example, the subscriber does not detect temperature alterations until we trigger the inject node.

Conclusion

We’ll stop there.

Learning to use IIoT technologies like Node-RED and MQTT can set you apart in industrial automation.

To assist you in your IIoT journey, we’ve created a course called IIoT Essentials: Node-RED & MQTT on PLCnext Technology in partnership with Phoenix Contact.

In this course, you’ll learn how to install, configure, and integrate these powerful tools and use them with hands-on projects.

Upon completion of the course, you will receive a certificate from Phoenix Contact.

Happy learning!

Join the Top 1% of Automation Engineers

Start Your 7-day Free Trial

Learn from Industry Experts

Start your learning journey today!
With a 7-day trial, then 25/month
Start Learning For Free