Skip to content

Edge Rules

Edge Xpert provides an open choice for executing rules at the edge. Both Kuiper and Node-RED are provided as out-of-the-box options, but the openness of the platform allows users to plug in their rules engine of choice.

In this tutorial, Node-RED is used to execute the basic rule of opening the Outlet-Valve (by setting its value to 1) when any of the Chemical Tank sensor values exceed 80.

Node-RED Setup

The tutorial project provides a pre-configured flows.json file that can simply be loaded into Node-RED. This can be done via the Node-RED Web UI or via its REST APIs which could be invoked on the command line.

Node-RED UI

  • In a web browser, navigate to http://localhost:1880
  • Add the Node-RED flow

    • Select Import from the top-right options menu
    • In Clipboard, click select a file to import and upload the flows.json file provided in the tutorial project
    • Click Import
    • Once loaded, select Deploy to deploy the flows

    NodeRED flow

Node-RED REST Command

As an alternative to using the Node-RED UI, Node-RED can be configured via its REST API as follows:

  • Upload the flows.json file:
    curl http://localhost:1880/flows -H "Content-Type:application/json" -X POST --data-binary "@flows.json"
    

Export to Node-RED

Notice that the Node-RED flow here uses MQTT to receive the data from Edge Xpert. The “Decision Making” function executes some simple JavaScript code to perform the control logic. The following instructions export the Edge Xpert data to MQTT so that Node-RED can receive the data and the logic flow starts.

Edge Xpert Manager UI

Use the Application Service onboarding wizard to create the export to MQTT:

  • Navigate to App Services in EdgeXpert Manager UI and select Add App Service Add App Service
    • Use the following data to add the App Service. Any fields not mentioned below should be left blank/default
Field Value
Name NodeRED
Destination MQTT
Broker Address tcp://mqtt-broker:1883
Topic MyTopic
  • See the screenshot from the Edge Xpert Manager below:

  • Click Save
  • Return to the Grafana dashboard. You should now see that the Outlet Valve will be opened (set to 1) when any of the Modbus values go above 80, as per the rule in the Node-RED flows.json:

  • Return to the Prosys OPC-UA Simulation Server. You should now see that the Outlet-Valve Setting parameter will be opened (set to 1) when any of the Modbus values are greater than 80:

Prosys outlet valve

  • Note that you may need to refresh the view inside Prosys order to see data updates

Command Line

As an alternative to using the Edge Xpert Manager UI, the above configuration can also be defined via an Application Service configuration file which can be started via command line. The tutorial project includes a nodered-mqtt.toml file with the same configuration as described above. It can be started as follows:

edgexpert up app-service -p nodered-mqtt.toml