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.
As a name, we assign the IoTWORKSHOPGADGETHPTG (IoTWORKSHOPGADGETH + our initials) and select the ThinKP that we created.
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’.
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’.
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’.
For each one of the previous Gadgets, you’ll create a chart like this:
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:
We get a table like this:
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’.
We’ll call it IoTWORKSHOPDASHBOARD + Our initials and we’ll check it as public. Press the ‘New Page’ button.
We enable editing mode.
Click on the + symbol that will allow us to add a new Gadget.
Select the Gadget type we want to add, in our case are three of Bar type and one of Table type.
Once the Gadget type is added, click on the Settings button.
Select the Gadget we want to add to our Dashboard.
The result will be the Dashboard with all the gadgets we have added.
In the Gadget listing, if we click on the link symbol,
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.
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.
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:
We must write a description and a value for the Meta-Inf field. Finally we can see the operations we can create.
Let’s create three CUSTOM, one for each type of data we store: Humidity, Temperature and Watts.
We should obtain the following three APIs:
We put the API as Published by clicking the ‘Publish’ button in the API listing.
Access to ‘My API Key’ menu, where we must copy the User Token, which we need to invoke APIs.
Access to ‘My Subscriptions’ menu, where the APIs we have published will appear.
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
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.
When we execute it we’ll get the query result we had defined.
.
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.
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!