Setting up Flowthings.io flows and tracks

By Anes

Setting up our flows and tracks used to store and sort our sensor feed drops.

Step 1

Preparing Flowthings flows and tracks

First thing we should do is to log in to our flowthings account and create flows which will receive data form our scraper (described below), and tracks which will be responsible for sorting drops between flows.

Follow the steps below

Step 2

Go to your home page

Click on the home link under Developers

Step 3

Flows overview

Click on Flows link to go to your flow overview page

Step 4

Create first flow

Next we are going to create our first flow.

Click on the New button to create a new flow
A popup will apear where we must fill in some details about our new flow

  • Path is our flow name, and an identifier by which we reference it later, name it sensor-feed
  • Description is just a basic description of our flow
  • We will leave filter empty, but we can use it to filter out data which comes in to our flow
  • Set capacity to 100000 - this is the maximum number of drops that can be stored in this flow

Now click on Save and voila, we have created our first flow :)

Step 5

Flow view

The newly created flow will be placed under /your-username/sensor-feed
In my case, my username is anes, yours will obiously be different.

  • Click on your username in the top left corner to go back to your flow overview page

Then we need to repeat actions from step 4 to create additional flows for each of our pollution measuring stations.

In our case we have three stations, we will name them:
- alipasino
- otoka
- ilidza

Step 7

Creating Tracks

To create tracks we can use the website interface just like we did when we were creating flows, but we are not going to.
Flowthings has an api endpoint for each action available. You can access full documentation here.

We will be using HTTP Track Create api endpoint and good old curl to create our tracks with custom filters.

In order to do this we will need to obtain our authentication token, by clicking on My Account link as shown on the image above.

Step 8

Creating Tracks

After you are presented with your account page, copy and paste your Master Token

Next thing you need to do is fire up your favourite terminal, in my case it is iterm, we will be using it to send api requests via curl to flowthings.io

Step 9

Creating tracks via api

First track we will be creating is a track from our sensor-feed flow to alipasino flow, by isuing following api request:

curl https://api.flowthings.io/v0.1/your-username/track 
    -H "X-Auth-Token: your-master-token" 
    -H "Content-Type: application/json" 
    -d '{
               "source":"/your-username/sensor-feed",
               "destination":"/your-username/alipasino",
               "filter":"elems.station.name == "alipasino""
          }'

Explanation:

  • https://api.flowthings.io/v0.1/your-username/track is an api endpoint used for creating a track where your-username should be replaced by your flowthings username.
  • -H “X-Auth-Token: your-master-token” is a required header we need to send in order to authenticate our selves with flowthings. your-master-token should be replaced with your master token obtained in previous step.
  • -H “Content-Type: application/json” is plain old content type header
  • Request body
-d '{
    "source":"/your-username/sensor-feed",
    "destination":"/your-username/alipasino",
    "filter":"elems.station.name == "alipasino""
}'

Request body in our case consists of JSON object which contains 3 parameters of concern.

  • First param source : /your-username/sensor-feed is path to our source flow which acts as origin
  • destination : /your-username/alipasino is path to our destination flow, your-username should be raplaced with your own in both cases

Filter parameter

This one requires a little more in depth explanation.

Since our drop is basically a JSON object which contains an elems key which is itself an object which contains any number of custom attributes (keys) which are user defined and are used to store our custom properties.

In our case, a simplified version of our drop would look like this:

{
    //drop meta
    "elems": {
        "pollution_index": 55,
        "station": {
            "name": "alipasino"
        }
    }
}

As you can se every drop will contain elems.station.name key which will define a station (flow) to which it belongs to, and we will be using it as a filter in order to determine our destination flow which represents a single station.

Now hit enter in order to send our request and proceed to the next step.

Step 10

Track

Now, visit your sensor-feed flow page, and you will see Tracks From (1) in the status bar which indicates that we have successfully created a track from our flow. Click on the notification to view your track.

Step 11

Track Inspector

Click on the View button and you will be presented with your track information. Notice that it contains parameters we sent in our request body.

Step 12

Creating a drop

To verify our track works as expected, we will create a new drop.
We will do that by going back to our sensor-feed page and clicking on New button as shown in the image above.

Step 13

Creating a drop

We will be presented with a popup dialog where we will fill out our drop object structure:

{
    "pollution_index": 55,
    "station": {
        "name": "alipasino"
    }
}

After filling out the form click on Save button to create our drop.

Step 14

Our new drop

As you can see, a new drop has been created in our sensor-feed flow

Step 15

Verifying that our track works

Now go to the alipasino flow and verify that you have a new drop which is magicaly created by our track from sensor-feed flow.

Step 16

TODO

Now, with your newly aquired knowledge on flowthings.io, create the two remaining tracks for otoka and ilidza stations.
It should be fairly simple, just revisit STEP 9 for a refresher.

Step 17

What's next

NodeJs scraper

In our next tutorial we will be explaining some bits behind nodejs scraper which will feed data into our newly created flows, see you there :)

Tutorial Forum

There are no posts here yet. Add the first post