Sofia2 IoT Workshop: Control panel. Gadget and Dashboard Creation. Publish Ontology as Api. (Part 3/4)

The goal of this workshop is the realization of a real example on wich we can evaluate the capabilities of Sofia2 platform.

 

To do this, we are going to simulate a building that has several floors, and three devices for the reading of energy consumption, temperature and humidity in each one of them.  Finally, we will create a dashboard to display this information and we will publish data in an API to be consumed in a simple way by any application.

 

In order to get a better understanding of the workshop, we will structure the steps to follow in 4 posts.

 

In previous posts we were working about:

 

(Part 1/4) – Data Model. Ontology. ThinKP.

 

(Part 2/4) – Simulate input data. Simulator Configuration and Execution.

 

We will see today (Part 3/4), in which we’ll create a Control Panel. We’ll create gadgets and a Dashboard. And we will learn how to publish Ontologies like Apis.

 

 

Control Panel

 

The next step is to create a Control Panel using the graphical presentation capabilities of the platform.

 

Gadget Creation

 

Go to ‘My Gadgets’ menu and click on ‘New Gadget’, select the Column type.

 

image230

 

As a name, we assign the IoTWORKSHOPGADGETHPTG (IoTWORKSHOPGADGETH + our initials) and select the ThinKP that we created.

 

image231

 

Select the ‘Get data from query’ tab, use the ‘select * from WorkshopIoTPTG where WorkshopIoTPTG.TYPE = ‘HUMIDITY’; And select as measures for the X axis ‘contextData.timestamp’, we must transform it using ‘new Date($0)’ and for the Y axis ‘HUMIDITY’.

 

image232

 

We’ll do the same to create the consumption graph of Watts, which we’ll call IoTWORKSHOPGADGETW + Our initials. In this case with the query ‘select * from WorkshopIoTPTG where WorkshopIoTPTG.TYPE = ‘WATTS’; Select as measures for the X axis ‘contextData.timestamp’, we must transform it using ‘new Date($0)’. And in the Y axis ‘WATTS’.

 

image233

 

And to create the temperature graph, which we’ll call IoTWORKSHOPGADGETT + Our initials. In this case with the query ‘select * from WorkshopIoTPTG where WorkshopIoTPTG.TYPE = ‘TEMPERATURE’. Select as measures for the X axis ‘contextData.timestamp’, we must transform it using ‘new Date($0)’, and in the Y-axis ‘TEMPERATURE’.

 

image234

 

For each one of the previous Gadgets, you’ll create a chart like this:

 

image259

 

Finally, we’ll create a table type Gadget, we’ll call it IoTWORKSHOPGADGETTABLE + Our initials, we’ll select the tab ‘Get live data’ and we’ll add the following columns:

 

image235

 

We get a table like this:

 

image236

 

Dashboard Creation

 

Once we have created the Gadgets, we are going to create a Dashboard that uses them, to do this, go to ‘My Dashboards’ menu and click on ‘New Dashboard’.

 

image237

 

We’ll call it IoTWORKSHOPDASHBOARD + Our initials and we’ll check it as public. Press the ‘New Page’ button.

 

image238

 

We enable editing mode.

 

image239

 

Click on the + symbol that will allow us to add a new Gadget.

 

image240

 

Select the Gadget type we want to add, in our case are three of Bar type and one of Table type.

 

image241

 

Once the Gadget type is added, click on the Settings button.

 

image242

 

Select the Gadget we want to add to our Dashboard.

 

image243

 

The result will be the Dashboard with all the gadgets we have added.

 

image244

 

In the Gadget listing, if we click on the link symbol,

 

image245

 

We have a dialog box with an URL where we can access and publish directly to the Dashboard.

 

 

Publish Ontology as API

 

Sofia2 allows us to publish our ontologies as REST Api , to do this we have to access to ‘My APIs’ menu.

 

image246

 

Click on  ‘New API’ button. We write the name IoTWORKSHOPAPI + Our initials, and we check it as public. Uncheck the option ‘External API’ and select our ontology.

 

image247

 

Let’s set a 5 minute cache for query results. And a limit of 5 API queries per minute.

 

We can see the EndPoint API access:

 

image248

 

We must write a description and a value for the Meta-Inf field. Finally we can see the operations we can create.

 

image249

 

Let’s create three CUSTOM, one for each type of data we store: Humidity, Temperature and Watts.

 

image250

We should obtain the following three APIs:

 

image251

 

We put the API as Published by clicking the ‘Publish’ button in the API listing.

 

image252

 

Access to ‘My API Key’ menu, where we must copy the User Token, which we need to invoke APIs.

 

image253

 

Access to ‘My Subscriptions’ menu, where the APIs we have published will appear.

 

 

image254

 

By clicking ‘Test & Doc’ we access to a page of API tests where, in the right part, appear the operations we have exposed.

 

\Humidity

\Temperature

\Watts

 

image255

 

When you click on each option, you’ll see the meta service information. At the bottom of the page we have the ‘Submit’ button. In the X-SOFIA2-APIKey header, paste the User Token that you copied in the previous point.

 

image256

 

When we execute it we’ll get the query result we had defined.

.

 

image257

 

At ‘Request Info’ tab we can see the invocation URL of the operation, which will be the End Point that was created when we generated the API and the operation.

 

image258

 

So far the third part of our IoT workshop.

 

In the next posts we’ll continue with the last part of the workshop and we’ll see how to create CEP rules, how to create SCRIPT rules and we’ll make a final exercise.

 

We wait for you!

 

 

Sofia2 IoT Workshop: Control panel. Gadget and Dashboard Creation. Publish Ontology as Api. (Part 3/4)

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s