User Tools

Site Tools


resource_encapsulation

Resource Encapsulation Programmer's Guide

Resource Encapsulation is an abstract layer which consists of common resource function modules. It provides functionalities for both the client and server side to ease the work of developers. For client side it provides Resource Cache and Broker functionalities (monitoring the presence of resource in the network). For server side it provides the simple and direct way to create the resource and to set the properties and attributes. For handling the request from client it provides flexibility to developer either auto control of request by the layer itself or developer control the request in the application. Namely, Resource Encapsulation provides the common function modules to make developer’s life easy.

Overall Architecture

This is an abstract view of the IoTivity architecture including the Resource Encapsulation layer of the IoTivity service.

IoTivity architecture depicting IoTivity services layer

Iotivity Service Component

This is a function module in the resource encapsulation layer. It monitors the presence status of the resource of user interest. It guarantees the presence status of the remote server (resource) selected & asked by application.

The IoTivity service layer consists of two sub layers:

• Service: This layer contains service modules which in-turn uses the functional modules of RE layer.
• Resource Encapsulation (RE): This layer consists of common functional modules.

The difference between both these layers is that the service layer has resource(s) to represent their features whereas RE layer do not have any resources.

Iotivity service architecture depicting service modules and function modules

Here the Resource Broker and Resource Cache are functional modules which provide the client side functionalities for the IoTivity services. The Resource client is an API layer on these functional modules to provide these functionalities to the developer in an abstract way. Server Builder is the functional module which provides server side APIs for easy creation of Resource and handling of requests. DiscoveryManager provides the resource discovery method which is responsible for monitoring late creation and join of user interested resources.

Components of Resource Encapsulation Layer

Resource Broker

This is a function module in the resource encapsulation layer. It monitors the presence status of the resource of user interest. It guarantees the presence status of the remote server (resource) selected & asked by application. Resource Broker flow

Resource Cache

This is another function module in the resource client side. It caches the attribute data of the resource of interest. It guarantees the delivery of the resource data selected & asked by application. It has different methods of caching the resource data as per developer’s requirements. These methods are specified in API section. Resource Cache flow

Resource Client

Resource Client is a common API layer for the developer to use Resource Cache and Resource Broker functionalities. It provides the APIs of “Resource Broker” and “Resource Cache” to the developers.

Server Builder

It is a functional module which handles the simplified creation of resources. In this module the developer does not need to deal with the details of CoAP communication, request and response handling. It provides APIs to ease the definition of resource types. The resources are defines based on the properties and developer has to provide the getter/setter methods. The developer does not have to worry about the request handling as it is taken care of internally in this module. Server builder flow

Discovery Manager

It is a functional module which handles the discovery for advertising/non-advertising remote resources. It means that, with this module, the resources could be discovered even though the resources do not advertise its presence by themselves. It will discover resources periodically (interval time for discovery is 60 seconds) until cancel for the discovery is requested. DiscoveryManager flow

C++ API usage

We can use Base layer API and Resource Encapsulation API together. Encapsulation API cover some common use cases, for detail configuration please use the base layer API.

IoTivity Framework initialization need to be done thru base layer API. e.g) OCPlatform (by default configuration, we can skip this step). [Doxygen] : resourceencapsulation.tar.gz

Sample Application : Resource Client & Server Builder

This section describes about the sample applications using the Resource Client and Server Builder APIs.

Linux

Build the Iotivity code for Linux platform. Refer: Primitive Services Guide

Working Flow

This section describes the working flow of the SampleResourceClient and SampleResourceServer Linux Applications. These sample applications show the functionalities provided by Resource Client (Common API layer over Resource Broker and Resource Cache) and Serverbuilder to ease the life of developer.

We have two linux applications :
- SampleResourceClient & SampleResourceServer (act as Temperature Sensor)

First run the SampleResourceServer:

~/iotivity/service/resource-encapsulation/examples/linux $ ./SampleResourceServer


Following logs will be shown:
Sample Application provides two options for presence.

To select an option, input the corresponding value for that option. For example if we select Presence On, input 1. Sample Application now provides two options regarding creation of the resource.
If we select the first option, it will create the resource and handling of all requests from client will be taken care internally by ResourceBuilder module.
If we select the second option, it will create the resource and handling of get and set request will be done by the application.

Now we will run the SampleResourceClient:

~/iotivity/service/resource-encapsulation/examples/linux $ ./SampleResourceClient

Following logs will be shown:
It gives two options, either to discover a resource or to quit the application. If discoverResource option is selected, application provides two more options as to what resource type is to be discovered. Discovery for light resource or temperature sensor can be made. On selecting Temperature Resource Discovery option, further options will be displayed to select the discovery type. This enquires the developer if discovery is to be unicast or multicast. In case of unicast discovery, the address needs to be input. In case of multicast discovery an empty string is passed by just passing a null string.

Tizen

Build Iotivity code
  • For building RE layer for Tizen platform run the following command in IoTivity root directory:
~/iotivity$ ./gbsbuild.sh 
  • It will build the Iotivity with default flags specified in the ~/iotivity/tools/tizen/iotivity.spec
  • Modify the iotivity.spec file as per the requirement.
  • Once build is successful it will generate the RPMS in the following folder:
~/GBS-ROOT/local/repos/tizen/armv7l/RPMS
  • Extract the following RPMS to get .so's [liboc.so, liboctbstack.so, liboc_logger.so, liboc_logger_core.so, libconnectivity_abstraction.so, librcs_client.so, librcs_common.so, librcs_server.so]:
    1. iotivity-1.0.1-0.armv7l.rpm [Versions are subject to change as per the release]
    2. iotivity-service-1.0.1-0.armv7l.rpm [Versions are subject to change as per the release]
  • Get the .so's [libboost_chrono.so, libboost_date_time.so, libboost_system.so, libboost_thread.so, libuuid.so] from:
    ~/GBS-ROOT-OIC/local/BUILD-ROOTS/scratch.armv7l.0/usr/lib/
Working Flow

This section describes the working flow of the RESampleClientApp and RESampleServerApp Tizen Applications. These sample applications show the functionalities provided by Resource Client (Common API layer over Resource Broker and Resource Cache) and Serverbuilder to ease the life of developer.
We have two tizen applications : RESampleClientApp & RESampleServerApp (act as Temperature Sensor)

Build and Import Procedure
  1. Import RESampleClientApp and RESampleServerApp applications from the given path : “service\resource-encapsulation\examples\tizen” to Tizen IDE. To import projects in tizen IDE, Go to File → Import → Tizen → Tizen Native Projects.
  2. Create a lib folder in RESampleClientApp and RESampleServerApp projects (if not present) and copy the required libraries (mentioned below) extracted from the generated RPM package as shown in section Build IoTivity code for Tizen Platform.

Required libraries are “liboc.so, liboctbstack.so, libuuid.so, liboc_logger.so, liboc_logger_core.so, libconnectivity_abstraction.so, librcs_client.so, librcs_common.so, librcs_server.so, libboost_date_time, libboost_system, libboost_thread and libboost_chrono.so”.

  1. Specify the path of the unzipped boost libraries in RESampleClientApp and RESampleServerApp projects in the way given mentioned below. (Unzip the boost libraries if not done already)

Right click the project in IDE → Properties → expand C/C++ Build → Settings → Tool Settings → select includes option under C++ Compiler → add the path of the unzipped boost libraries in the include paths area → Apply → OK.

  1. Clean and build RESampleClientApp and RESampleServerApp projects and launch the applications in Tizen 2.3 device.
Running Applications

In the case of sample applications both created as well as discovered resource is a temperature sensor resource. Sample Server Application provides two options for creation of a temperature resource.

  • Auto control : It creates a temperature resource and handling of all requests from client will be taken care internally by ResourceBuilder module.
  • Developer control : It creates a temperature resource and handling of all get and set requests from client will be taken care by the application(i.e. developer).

Sample Client Application provides a single option to discover the resource of interest. Only once the resource has been discovered remaining options will be displayed for the found resource. Home screen for both the sample applications are shown below :

  • Server screens

Server screenServer screen

  • Client screens

Client screen

Server with Auto Control

Run the RESampleServerApp: Select the only option provided to create a temperature resource. As this resource is created with auto control option, the server set and get requests handling will be done internally by ResourceBuilder module. Application will just create the resource, set the resource properties and attributes(i.e. temperature value). The sample screen with logs is shown below.

Run the RESampleClientApp: Select the start discovery option. Wait until a found resource callback is printed in the log box. If it is the desired resource you are looking for, press cancel discovery, else keep the discovery running. The application looks for a temperature resource and on successful discovery prints the resource URI and host name. The sample screen with logs is shown below.

Client screen Client screen

Android

Working Flow

This section describes the working flow of the RESampleClientApp and RESampleServerApp Android Applications.

These sample applications show the functionalities provided by Resource Client (Common API layer over Resource Broker and Resource Cache) and Serverbuilder to ease the life of developer.

Build Procedure

Build the Iotivity code for Android platform. Refer: Primitive Services Guide

Note: Once build is succeed it will generate the RE samples .apk in the following directory:

  • RE Client : ~/service/resource-encapsulation/examples/android/RESampleClientApp/app/build/outputs/apk
  • RE Server : ~/service/resource-encapsulation/examples/android/RESampleServerApp/app/build/outputs/apk
Running Applications

In the case of sample applications both created as well as discovered resource is a temperature sensor resource. Sample Server Application provides two options for creation of a temperature resource.

  1. Simple Server : creates a temperature resource and handling of all requests from client will be taken care internally by ResourceBuilder module.
  2. Custom Server : creates a temperature resource and handling of all get and set requests from client will be taken care by the application(i.e. developer).

Sample Client Application provides a single option to discover the resource of interest. Only once the resource has been discovered remaining options will be displayed for the found resource. Home screen for both the sample applications are shown below :

Run the RESampleServerApp: Select ‘SIMPLE SERVER’, press the ‘START’ button to start the server resource. As this resource does not set any handlers, the server set and get requests handling will be done internally by ServerBuilder module. Application will just create the resource, set the resource properties and attributes(i.e. temperature value). The sample screen with logs is shown below.

Run the RESampleClientApp: Press the ‘DISCOVERY RESOURCE’ button. Wait until a found resource callback is printed in the log box. The application looks for a temperature resource and on successful discovery prints the resource URI and host name and control options will be shown. The sample screen with logs is shown below.

Server screen Client screen

Details are similar to tizen sample applications.

resource_encapsulation.txt · Last modified: 2017/05/12 13:16 by Jay Sharma