Revision for “Creating IoT Resources” created on February 27, 2015 @ 13:36:29
Creating IoT Resources
The IoTResource Builder allows you to define your IoTResources and automatically generate the necessary IoTResource code stubs. Services can then be built using these IoTResources. The IoTResources are typically used to interface IoTThings (various networked devices, or physical objects associated with devices) in some IoTWorld. <h3>Creating services with actions and state variables</h3> Below is a step by step walk through on how to create service access points to IoT Resources. To do this, we need to create a Service including a set of Service Actions and their related State Variables. In the case below we will define a service, with related annotations and actions, for an Air Quality monitoring device. This device can be used to read CO2 values measured in ppm´s (parts per million) as an indication of the current indoor air quality (IDA). The air quality can then be presented either as an absolute CO2 value, or, as named intervals: High, Medium, Moderate or Low air quality (formally referred to as IDA1-IDA4 in the EN13779 standard). Each interval defines a CO2 range, e.g., IDA1 (High) is 0 - 400 ppm's CO2. <h4>Name and describe the service</h4> The first step is to name the service and provide some basic annotations (meta data descriptions) in order to facilitate discovery and help others to understand the service semantics. <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ServiceAnnotations1.png"><img class="alignnone size-full wp-image-643" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ServiceAnnotations1.png" alt="RB_ServiceAnnotations" width="693" height="554" /></a> As can be seen from the Service annotation above, this service should return two alternative measures: a value for the CO2 level in ppm, or in terms of named intervals following the air quality standard. Following this the needed set of Actions (methods) and effects for this service should analysed and decided. <h4>Create State Variables for the Actions</h4> Continue to define the returns from the actions. Most actions will need to have their own State Variables defined, in this service they will be used to hold the return values of actions. In some cases state variables may also be needed as input arguments to actions. <h5>A State Variable for the CO2 level</h5> This variable will hold a simple CO2 value. The unit is ppm, based on a simple type . <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_StateVarCO2Level.png"><img class="alignnone size-full wp-image-630" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_StateVarCO2Level.png" alt="RB_StateVarCO2Level" width="400" height="547" /></a> It is good practice to provide some annotations also for the State Variables, at minimum a description, and above also the unit (ppm). The Reference field can be used to point at some external source used to describe this variable (some controlled vocabulary, or even an ontology). <h5>A State Variable for Air Quality in intervals of ppm (IDA)</h5> The next variable is a bit more interresting, since is also should include a custom value set. This is for representing the CO2 intervals mentioned above (named IDA1 - IDA4). <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_StateVarAirQuality.png"><img class="alignnone size-full wp-image-629" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_StateVarAirQuality.png" alt="RB_StateVarAirQuality" width="450" height="650" /></a> The UoM is her denoted as IDA, and we use the Reference annotation to make a link to the European standard on which these CO2 intrervals are based. The link is further explained in the Descriptions field. Looking at the State Variables Tab we see the current set of defiend variables. <h5>Summary Tab with the state variables for <em>ppm</em> and <em>IDA intervals</em></h5> <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_StateVarTab.png"><img class="alignnone size-full wp-image-631" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_StateVarTab.png" alt="RB_StateVarTab" width="668" height="343" /></a> We continue with the definitions of the Actions to be associated with the above variables. <h4>Create Actions for the Service</h4> For this Service we will define two actions that are going to be used to retrieve sensor values (IoTObservations) from the Air Quality Device, using the state variables above. The first action will get the current (last available) CO2 value from the sensor device, in ppm (parts per million). A third Action will be added, which can be used to Turn On/Off the device. <h5>Create an Action to return the CO2 level in ppm's</h5> Provide the name and a short description. Then select the orresponding state variable is selected in the Aurgument List. <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionGetCO2Level1.png"><img class="alignnone size-full wp-image-646" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionGetCO2Level1.png" alt="RB_ActionGetCO2Level" width="435" height="593" /></a> Actions can also be annotated with a list of possible Effects they might have in the applications context, or more specifically on other state variables. As an example, turning off a fan might cause a temperature raise, and perhaps also a decrease in energy consumption. Note that these "effects" are not to be seen as hard dependencies between actions/ state variables maintained by the service run-time, but rather as a way to document possible effects in the application context and IoT Domain. The effect annotations can then, like all service annotations, be made searchable for developers as an aid in service development. <h5>Action for retrieving Indoor Air Quality (IDA) in ppm intervals.</h5> In order to return the CO2 in ppm intervals we link the action to the previousle defined state variable with the value set for IDA intervals. <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionGetIndoorAirQuality.png"><img class="alignnone size-full wp-image-633" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionGetIndoorAirQuality.png" alt="RB_ActionGetIndoorAirQuality" width="465" height="554" /></a> We also provide a link the EU standard in the Reference field. <h5>Finally we also add an action for turning the sensor device off.</h5> <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionToggleCO2Sensor.png"><img class="alignnone size-full wp-image-635" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionToggleCO2Sensor.png" alt="RB_ActionToggleCO2Sensor" width="466" height="623" /></a> For this action we also add an effect annotation, which simply states that at turn off, the latest observation will be cached. <h3>Summary list of Actions and State Variables for the Service</h3> <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionTab.png"><img class="alignnone size-full wp-image-634" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_ActionTab.png" alt="RB_ActionTab" width="608" height="311" /></a> <h3>Generate the code stub for this IoTResource</h3> Now the code stubs for the Service and the IoTResource specified can be genererated. <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_GenerateResourceStub.png"><img class="alignnone size-full wp-image-627" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_GenerateResourceStub.png" alt="RB_GenerateResourceStub" width="417" height="660" /></a> The generated results include the Service definition in XML, as well as the development project files. The generated VS project is shown below. <a href="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_VS_CO2SensorResource.png"><img class="alignnone wp-image-642" src="http://www.iotworldservices.com/wp-content/uploads/2014/12/RB_VS_CO2SensorResource.png" alt="RB_VS_CO2SensorResource" width="743" height="530" /></a> This project can then be used by the developer to extend and refine the the service logics, for example, the GetIndoorAirQuality action above needs to provide code for the mapping of the ppm intervals. The following XML encodes the resulting Service definitions.