Node-RED
Node-Red Overview
Node-RED is a programming tool that provides a browser-based flow editor that makes it easy to wire together flows using nodes in the Node-RED palette. This example shows how you can use Edge Xpert to deliver the data to Node-RED. Once the data is in Node-RED, you can create rules and analytics to handle the data or send commands back to Edge Xpert.
The following example demonstrates how to set up and use Node-RED. We use the Virtual Device Service to send data to Edge Xpert. The data is exported to the MQTT broker by using the Application Service and then publish to Node-RED. Finally, a subscription is set up in Node-Red to subscribe to the data from Edge Xpert.
Steps are as follows:
- Start the Edge Xpert
- Export events to a MQTT-broker using the Application Service
- Set up a Subscription in Node-Red
Start the Edge Xpert Services
In this example, we are using Node-RED, the MQTT broker and the Virtual Device Service. We are also going to use the Xpert Manager to set up the Application Service to export events to the mqtt-broker
. Start Edge Xpert using the command:
edgexpert up nodered mqtt-broker device-virtual sys-mgmt xpert-manager
Export Events to a MQTT-Broker Using the Xpert Manager
We are going to export events to a MQTT broker via the Application Service. For more information on using the Application Service see Application Service.
In the following example, we use the Application Service Onboarding Wizard with the Xpert Manager.
-
To bring up the Xpert Manager, navigate to
localhost:9090
in a web browser. Enter the user name and password (the default user name and password is admin). See Edge XPert Manager UI for more information. -
Go to the Application Services tab and click the Add App Service (+) button.
-
Enter the following information and click the save button to complete the process.
Field | Value |
---|---|
Name | NodeRed |
Destination | MQTT |
Broker Address | tcp://mqtt-broker:1883 |
Topic | MyTopic |
Set Up a Subscription in Node-RED
To set up Node-RED to subscribe to the data from Edge Xpert complete the following steps:
- Open a browser and enter
localhost:1880
to start the Node-RED user interface. - Drag mqtt-in from the network options to the flow, as shown below:
- Double-click the mqtt input node to edit the node properties.
- Select the Edit (pencil) icon beside the Server field, as illustrated below:
- In the Name text box, enter mqtt
- In the Server text box, enter mqtt-broker
- Click the Add button
-
In the Topic text box, enter MyTopic
-
Select the Done button.
- Drag json from the parser to flow, as illustrated below:
- Drag debug from the common options to flow, as illustrated below:
- Drag the connector box on the right of the mqtt node to the json node. Then drag the connector box on the json node to the debug node as shown below:
- Select the Deploy button.
- Select the debug node, then select Debug Messages (bug) icon, as illustrated below. Now you can see the data from Edge Xpert in the Debug Messages panel.