In this guide we will start by creating a basic example Flow. It doesn't connect to any external system, the goal is just to get you familiarized with the concept of building and testing Flows. We will use an internal data source, aggregate some values and send the result to the internal MQTT broker.
Flows are created and managed in the Flow Studio. You access the Flow Studio using the button in the upper left corner of each page. Once you've built a Flow you can also open it in the editor from the Flows page. For an introduction to the Flow Studio, see here.
Follow these steps to start creating your first Flow
Open the Flow Studio using the "Flow Studio" button to the left in the top menu. You should now see an empty Flow.
The starting point is the library of pre-built modules, available on the left side of the drawing canvas by clicking on the button in the menu bar. There are three categories of modules:
Input modules - Gets data from internal or external sources, such as time triggers, APIs and PLCs.
Analytics modules - Process the data in some way, or specifies conditional triggers based on the data.
Output modules - Delivers processed data or triggers to external systems.
We will start by adding an internal data source to our Flow. Find the Data Generator module in the list and drag and drop in the main Flow page (you can use search to find a specific module). This module can be used to generate different types of test data.
To change module setting, hover over the module with the mouse and click on the cogwheel () button to open the settings panel.
The settings panel has three tabs:
Settings - Module specific settings.
Common - Settings that are available on all modules. We leave them for now.
Documentation - Documentation on the module and its settings.
Now you need to add the relevant settings for the Data Generator. Scroll down to the JSON input field and click on "Add example". All other settings you can leave as they are for now.
Now we will add the rest of the needed modules.
First locate the Aggregate module in the Analytics modules list and drag and drop into the Flow.
Connect the Data Generator module with the Aggregate module by dragging the connection from the Data Generator module to the Aggregate module.
Now locate the MQTT Pub Broker module in the Output module list and drag and drop it to the right of the Aggregate module. Then connect the Aggregate module with the MQTT Pub Broker module.
The Flow should now look like below:
Module settings
Now we need to add the relevant settings for the Aggregate module.
Open the settings panel and make the following changes:
Source Property - Should be name
Value Property - Should be data.temp
Target Property - Should be aggregate
Mode - Should be set to Count
Count - Should be set to 5
For the MQTT Pub Broker module, set Topic to foo/bar and Source Property to aggregate.
Note how the property settings determine how each module use message data.
Now it is time to save your Flow.
Click Save in the lower right corner to save the Flow. You will now be asked to provide a name for the Flow and a short description that describes what the Flow does. Click Create to store your new Flow.
Next step is to test your Flow, see .
In the next example we will use some external services. We start by polling a service that delivers random Chuck Norris quotes through a REST API. Then we extract the relevant data from the response and send it to a Slack channel.
Follow these steps to create the Flow
Prerequisites
You’ll need the following to complete the tutorial:
Building the Flow
Create a new Flow in the Flow Studio
Add an Interval module and set the interval to 0. This module generates repetitive triggers at the specified interval. By setting the interval to 0 and having "Run on start" set to true the module will trigger once when the Flow starts.
Next we will make a request to the Chuck Norris service. The easiest way is to add the dedicated Chuck Norris GET Random Joke module. If you want to try a more generic approach you can also use the HTTP Request module and set the URL to https://api.chucknorris.io/jokes/random. In the next steps we assume you use the Chuck Norris module.
At this stage it's a good idea to test what we've built so far, so we can see what the response from the Chuck Norris service looks like. Start a remote session, enable debugging on the Chuck Norris module and start your Flow. It can be hard to see the full response in the debug window. Use the menu on the message to open it in a separate pop-up window. As you will see you get a rather complex message from this module. The joke that we are interested in is nested in the hierarchy of the message. To reference the joke text we use the following syntax: cn_joke.body.value.
Next we want to use the joke and create a message that we can send to our Slack channel. To do that we will add a Text Template module. With this module you can add generic text to your message and in the text reference data from the incoming messages. Any property references you put inside {} will be replaced by the corresponding value from the messages. Add the following settings:
Target Property - Set to: data.text
Template - Set to: Check out this joke: {cn_joke.body.value}
Now run the Flow again but enable debugging on the Text Template module. Make sure you get the expected result on the data.text property.
As the last step will will add an output module, in this case the Slack module. To use this module you need to create a webhook in your Slack account, see the link above for instructions.
Make the following changes to the settings:
Webhook URL - Set to the webhook you created
Channel - Set to the name of the Slack channel where you want to publish your message
Username - Set to your Slack username
As you see there is a text field in the module settings where you can enter a message text. If you use this field the same message will be sent each time. In this case we want to use message text from the incoming messages. With this module all settings except the Source Property can come either from the settings or from the incoming message. If you leave a settings field blank the module will expect to find the information on the relevant property in the object assigned to the Source Property. In our case we wanted to take the message text from the message and therefore we assigned the text to the data.text property in the Text Template module and then set the Source Property in the Slack module to data. You can read more about this in the module documentation, by opening the Documentation panel from the module settings.
After completing this exercise you should have built a Flow similar to this: