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. In this example we are going to use the Virtual Device Service to send data to Edge Xpert. The data is exported to an MQTT broker using the Application Service which will publish it to Node-RED. Finally, a subscription is set up in Node-Red to subscribe to the data from Edge Xpert.
These are the steps:
- Start the Edge Xpert services
- 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 --secret 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 To make things easy we are going to use the Application Service Onboarding Wizard in 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 about using the Xpert Manager.
Go to the App Services tab and click the Add App Service (+) button.
Enter the following information
Click the save button to save the application service setup.
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 in the Address Bar 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. You can see the data from Edge Xpert in the Debug Messages panel.