Introduction
With Data Flow Manager you can build your own logic or manipulate data, by creating a flow made up by multiple nodes (premium extension), each of them implementing a basic functionality
The Flow Editor provides a simple drag and drop interface where you can quickly build powerful flows to work with payloads published by your Things, and get that data out to wherever you need it.
CloudLocate flow
To create your first flow, just select Flows from the sidebar and click create flow on the top right corner of the screen to create a new flow. Assign it a name and then create your flow adding the CloudLocate node and any other other nodes you need. You'll find details of the input and output parameters for each node in the info tab on the right-hand side of the editor.
The following picture shows an example of how to build a flow that receives a measurement, calculates the position and sends the result by email.
The logic behind a flow is that:
All devices (Things) send the data to the platform on a given MQTT topic
The flow subscribes to this given topic and any data published to the topic triggers the execution of the flow.
You can connect multiple nodes, with a simple drag and drop, creating complex functions and logic, manipulating data before sending it to your cloud application, and using multiple channels (SMS, mail, MQTT, HTTP(s), FTP(s) etc.)
The next sections cover configuration of the nodes shown in the example above, and how to execute your flow. For detailed information about using Flows, have a look at the Flows documentation.
CloudLocate node
This node calls the CloudLocate service to calculate a position based on incoming measurement data. The result becomes an input to the next node in the flow.
The node accepts the input in two format:
a pure binary payload:
-
the JSON format with or without date and time field, depending if you are sending fresh data or measurements generated more than 60 seconds ago
the body shall contain the Base64 encoded measurements.
Msg.payload (debug) node
This node is used for debugging purposes. It will output debug data to the "debug" tab on the right-hand side, so that you can immediately see results of the connected node(s).
Set email recipient (function) node
This JavaScript function node can be used to set an email address to be used by the email node by using the following code
/*
Set the email "to" address to the
domain owners email address.
*/
msg.to = msg.domainOwner.email;
return msg; You can also specify any email address if you want to send an email to a recipient other than the domain owner, like:
msg.to ="me@mydomain.com";
return msg; You need to add the above code in the function node by double-clicking on the node to open the configuration options and click "Done" to save your changes.
Email payload node
This node will send an email with the estimated position. You don't need to configure the email recipient details directly in the node as they are set in the previous JavaScript function node.
Executing your flow
You'll need to deploy your flow so that you can test it. Use the "Manage" button in the top right corner of the flow editor and deploy the flow in test mode
You can use an MQTT Now (IP Thing) in the platform to act as a client for publishing the GNSS data.
Select the Services -> Things item on the left sidebar
Click on Add Thing and then on 'Add new IP Thing'; give it a name
Select a plan. For test purpose you can select the developer plan
In the credential section of each IP Thing you can find the MQTT credentials and endpoint. Use this information to configure an MQTT client in your laptop or in your real device.
If you don't have an MQTT client, you can use our publish API instead https://api.thingstream.io/swagger#!/Publish_API_Webservice/publishTopicString This will convert the HTTP POST to an MQTT message and trigger the flow
Here is an example of a working request body, you just need to update the deviceId to the one for the IP Thing created above, and the content part to the MEASX data from your receiver
{
"deviceId": "device:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"qos": 0,
"retained": false,
"topic": "CloudLocate",
"content": "{\n\t\"GNSSMeasurements\": {\n\t\"Payload\":\"tWIChjIAG/M7CcimDqBmvpr+A9pGYVEPdxhiyIqPToNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAA==\",\n\t\"DateTime\": \"2023-04-05T12:50:16\"\n\n\t\t\t }\n\t\t}\n}"}
The cURL looks like this (get the API key and secret from https://portal.thingstream.io/app/account/domain-settings)
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "X-Auth-Key: <key>" --header "X-Auth-Secret: <secret>" -d "{
\"deviceId\": \"device:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",
\"qos\": 0,
\"retained\": false,
\"topic\": \"CloudLocate\",
\"content\": \"{\n\t\\"GNSSMeasurements\\": {\n\t\\"Payload\\":\\"tWIChjIAG/M7CcimDqBmvpr+A9pGYVEPdxhiyIqPToNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAA==\\",\n\t\\"DateTime\\": \\"2023-04-05T12:50:16\\"\n\n\t\t\t }\n\t\t}\n}\"}" "https://api.thingstream.io/publish/topic/string"
Thingstream inject node
You can also inject sample data and execute the flow directly from the flow editor This can be very helpful when writing and debugging your flows.
You can position this node anywhere in your flow and use it to test the flow execution from the point.
To configure this node, double-click on it:
In the search field type the name of the IP thing that you have just created before to filter the list of the Things available in the box below and select it
Specify the MQTT topic where your message would be published to . This is a mandatory field for this node, but for the on going test you can specify any topic e.g. 'CloudLocate'
select JSON as Payload Format
give a JSON payload of the measurement (you can simply copy and paste the sample measurement given here below)
Click "Save Flow" to save your changes
To run this node, simply click on the filled square on the left-hand side of the node. You'll be able to review any debug output in the debug tab on the right-hand side of the editor.
Before running the flow, you will be asked to save it (the Save button is on the top right of the editor window).
{
"RequestId": "82cb34c9-88c9",
"GNSSMeasurements": {
"Payload":"tWIChjIAG/M7CcimDqBmvpr+A9pGYVEPdxhiyIqPToNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAA==",
"DateTime": "2023-04-05T12:50:16"
}
}
Still need help?
If you need more help or have any questions, please send an email to services-support@u-blox.com.