Programmers Guide Primitive Service
Programmers Guide Primitive Service
Primitive Service
1 CONTENTS
2
Terminology .......................................................................................................................................... 4
3.1.1
3.1.2
3.2
3.3
3.4
4.2
4.3
4.3.1
4.3.2
4.3.3
4.3.4
4.3.5
Discovery Manager................................................................................................................ 13
4.4
4.4.1
Linux ...................................................................................................................................... 14
4.4.2
Tizen ...................................................................................................................................... 15
4.4.3
Android .................................................................................................................................. 18
Resource Container............................................................................................................................. 20
5.1
5.1.1
5.1.2
5.2
5.2.1
Linux ...................................................................................................................................... 27
5.2.2
Tizen ...................................................................................................................................... 28
5.2.3
Android .................................................................................................................................. 31
Things Manager................................................................................................................................... 35
6.1
6.1.1
Linux ...................................................................................................................................... 37
6.1.2
Tizen ...................................................................................................................................... 62
6.1.3
Android .................................................................................................................................. 83
7.1.1
7.1.2
7.1.3
8.1.1
8.1.2
Mediator.............................................................................................................................. 121
8.1.3
8.2
8.2.1
Negotiation.......................................................................................................................... 121
8.2.2
8.2.3
8.2.4
8.3
8.3.1
8.3.2
8.4
8.5
8.5.1
2 TERMINOLOGY
Resource Encapsulation
It is an abstract layer which consists of common resource function modules.
Resource Broker
It is function module of Resource Encapsulation layer which monitors the presence status of the
Resource of Interest.
Resource Cache
It is the function module of Resource Encapsulation layer which manages the caching of Resource data.
Resource Client
It is the common API layer for the Resource Cache and Resource Broker module.
Server Builder
It is module which provides easy creation of resource with flexibility of handling the request either
internally by module itself or at application level.
Resource Container
It provides the APIs for integration of non-OIC resources into OIC ecosystem.
Resource Bundle
It contains the resource information of non-OIC devices, which is used to create OIC resources.
Things Manager
An abstracted service which comprises 2 sub services: Group management and Things
configuration/maintenance service.
Group
A set of devices in an IoTivity local network and remote networks for accomplishing the specific goal.
Using several kinds of criteria, devices can be a member of a specific group. However, basically those
member devices dont have any information about the group. Only the device that creates this group
can have and maintain the information about this group.
Currently, resource type can be used as criteria for group formation and more criteria will be provided
later.
ActionSet
A set of action descriptions needed by remote devices as the member of a specific group. For a
particular group, multiple actions set can be assigned to this group. One action set can have multiple
actions and one action should be assigned to one specific member devices characteristic. Currently only
resource type can be used as devices characteristic.
To create an action set, one may need to know the Delimiter serialization. With the Delimiter, one
specifies an action set as below.
movieTime*10 1*uri=coap://10.251.44.228:49858/a/light|power=on*
uri=coap://10.251.44.228:49858/a/light|power=on
A first segment before the first asterisk(*) is an action set name. The second segment indicates a timerelated information which is used for scheduled/recursive group action features. The first digit in the
segment is either delay or a step of time delay and the second digit is a type of group action, e.g., a
normal/scheduled/recursive group action. If the type indicates a normal group action, the first digit will
be ignored. If the type does a scheduled group action, the first digit will be utilized as a time delay such
as after 10 seconds. If the type does a recursive group action, the first digit will be utilized as a step of
time delay such as every 10 seconds.
The third segment goes before a next asterisk. In the above example,
uri=coap://10.251.44.228:49858/a/light|power=on is the segment. This can be also divided into two
sub segments by a vertical bar(|): URI and a pair of attribute key and value.
The remained string from the second asterisk is same as the third segment.
Group Manager
A software service which helps to shape a specific group and maintain that group. Group action feature creating, maintaining and executing group action related with this group also provided by Group
Manager.
Things Configuration
A Things Configuration class provides several APIs to access a Configuration resources value to
get/update a system parameter. The extent of what a Configuration resource covers could be all systemspecific parameters. In this release, a Configuration resource partially covers system parameters on a
device name, location, and currency information.
Things Maintenance
The purpose of a Things Maintenance is to request a system command (e.g., Factory Reset, Reboot) with
a maintenance purpose to a resource server by accessing a Maintenance resources value from a client
remote in distance.
3 BUILD INSTRUCTIONS
This section covers Cloning of Iotivity code and build instructions for Iotivity code.
ssh
Secure Shell is required to connect to the git repository to check out the IoTivity source code. Secure
Shell is typically part of the base operating system and should be included. If for any reason it is not
available, it can be installed by running the following command in your terminal window:
$ sudo apt-get install ssh
SCons
SCons is build tool used for compiling IoTivity source code. It can be installed by running the following
command n your terminal window, otherwise you can refer to the following link to install SCons.
$ sudo apt-get install scons
http://www.scons.org/doc/production/HTML/scons-user.html#chap-build-install
Doxygen
Doxygen is a documentation generation tool used to generate API documentation for the IoTivity
project. Download and install doxygen by running following command in your terminal window.
For example: Jay Sharma with an email address jay.sharma@samsung.com would type:
$ ssh-keygen t rsa C Jay Sharma jay.sharma@samsung.com
After pressing the Enter key at several prompts, an ssh key-pair will be created at ~/.ssh/id_rsa.pub.
Hostname gerrit.iotivity.org
IdentityFile ~/.ssh/id_rsa
User [Insert_your_username_here]
Port 29418
c. To connect behind the proxy, add the following line after IdentityFile ~/.ssh/id_rsa with the
appropriate proxy address and port:
ProxyCommand nc X5 x <proxy-address>:<port> %h %p
Step 4: Verify your ssh connection
Execute the following command in the terminal window:
$ ssh gerrit.iotivity.org
Upon successful connection, the following message should appear indicating proper ssh and
configuration connection.
**** Welcome to Gerrit Code Review ****
If the connection is not established, check for the proxy and use the proxy settings described in Step 3.
Step 5: Cloning the project source
To build the IoTivity resource stack:
a. Using your terminal window, browse to the directory where code will be checked out.
b. Execute the following command in the terminal window to clone the iotivity repository:
$ git clone ssh://gerrit.iotivity.org/iotivity
The above command clones the repository in your current working directory.
If the build is successful you will see an out/linux folder in Iotivity directory.
If the build is successful you will see the following build success logs:
4 RESOURCE ENCAPSULATION
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
developers life easy.
Service:
This layer contains service modules which in-turn uses the functional modules of RE layer.
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.
Figure 2: 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.
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.
4.3.2
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 developers requirements. These methods are
specified in API section.
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.
Linux
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
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.
4.4.2
Tizen
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_container.so, librcs_server.so, libboost_date_time, libboost_system and
libboost_thread.
3. 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.
4. Clean and build RESampleClientApp and RESampleServerApp projects and launch the
applications in Tizen 2.3 device.
4.4.2.3 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.
a) Auto control : It creates a temperature resource and handling of all requests from client will be
taken care internally by ResourceBuilder module.
b) 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 Screen
Client Screen
4.4.2.4 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.
4.4.3
Android
2) Create libs folder in app folder each of RESampleClientApp and RESampleServerApp projects
(if not present) and copy the required libraries.
- iotivity-{TARGET_ARCH}-base-{MODE}.aar located in
android/android_api/base/build/outputs/aar
- iotivity-{TARGET_ARCH}-service-{MODE}.aar located in
service/resource-encapsulation/android/service/build/outputs/aar
where TARGET_ARCH is a build option for scons of iotivity and where MODE is release or debug.
3) Clean and build RESampleClientApp and RESampleServerApp projects and launch the
applications.
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.
5 RESOURCE CONTAINER
The main purpose of this functional module is to:
Dynamic loading of resources bundles. One resource bundle can contain multiple resources.
Bundle is activated by the container and bundle registers its resources at the resource container
re-using the features of the other Resource Encapsulation layer components.
Provides common resource templates and configuration mechanism for resource bundles. It
deals with OIC specific communication features, and provides common functionalities in a
generic way.
It provides APIs to activate and deactivate resource instance(s) dynamically on demand.
Figure 7 illustrates the architecture of the resource container. It offers a container API that can be used
to start the container. A common XML configuration file is used for all resource bundles. The
configuration contains parameters specific to the bundle but also to every resource instance. A resource
bundle contains an activator and bundle resources. A bundle resource can be the definition of a soft
sensor(= logical sensor, virtual sensor) resource that contains an algorithm to derive new knowledge
and offer it as a resource and protocol bridge resources which map other technologies to OIC resources.
The bundles only contain the mapping logic, whereas the actual creation of OIC resource servers
happens in the resource container. The bundle provider is agnostic of the base and resource
encapsulation layer APIs of IoTivity and only needs to adhere to the bundle API.
The resource container is a component used by many different stakeholders. The main stakeholders are
device manufacturers that provide a device bridge to other technologies, a bundle provider providing
bundles that map other technologies to IoTivity or offer software-defined resources (e.g. algorithms,
sensor fusioning), system integrator or end-user which configure the resource container and its bundles
for a concrete environment. For an application developer the resource container is transparent and the
developer has only to adhere to the OIC specified interfaces. A stakeholder overview is given in Figure 8,
and the interaction flow for the activation of a bundle is shown in Figure 9.
Device
Manufacturer
(Bridge)
Bundle Provider
System
Integrator/System
administrator/End
user
Application
developer
The root element of the configuration is the container element which contains an arbitrary number of
bundle elements specifying the configuration of bundles. For configuration of the bundle an id, path,
activator ,version and resources need to be configured. The identifier should be a string uniquely
identifying the bundle. A hierarchical naming scheme like a domain name is desirable but an arbitraty
string can be chosen. The path references the local path of the bundle location relative to the executing
application. The activator holds bundle specific information of the activation code that needs to be
triggered if a bundle is started. For C++ bundles, this is a name prefix of a static activation function, for
Java it is a class name.
The resources element encapsulates all resource specific information. A resource element covers
here the configuration of a single resource instance. The bundle contains resource type specific classes
that map the interaction for a specific protocol or soft sensor. The resource element provides all
instance specific configuration. A bundle can contain multiple resources, and each resource is described
with the resourceInfo element. Mandatory elements of the resource configuration are name and
resourceType and resourceUri. In addition to the mandatory fields, arbitrary technology specific
information for the resource can be included in the configuration file. A soft sensor resource could
further provide resource configuration for inputs. In this case the resource container can take care to
acquire the according data from the according input resources. Output attributes can either be listed in
the configuration or programmatically inside the soft sensor implementation.
<resources>
<resourceInfo>
<name>DiscomfortIndexSensor1</name>
<resourceType>oic.r.sensor</resourceType>
<outputs>
<output>
<name>discomfortIndex</name>
<type>int</type>
</output>
<output>
<name>humidity</name>
<type>double</type>
</output>
<output>
<name>temperature</name>
A resource bundle should implement the BundleActivator interface to define an activator. The following
external functions also need to be defined, and trigger the creation and the execution of the activator.
The prefix of the external functions should be the same as the activator described in the bundle
configuration file.
extern "C" void huesample_externalActivateBundle(ResourceContainerBundleAPI
*resourceContainer, std::string bundleId)
{
bundle = new HueSampleBundleActivator();
bundle->activateBundle(resourceContainer, bundleId);
}
To define resource classes, the resource bundle should implement ProtocolBridgeResource and
SoftSensorResource interface to define resources for each protocol bridge and soft sensor bundle.
5.1.1.2 Build instructions
To build the bundle API and a C++ resource bundle, include the header files of the bundle-api into a new
project and provide the resource container library.
Scons can be used to create a resource library. The Sconscript of the resourceContainer shows how to
build a resource bundle.
5.1.2 Java Bundle APIs and Project Template
A Java bundle offers the capability to reuse existing Java-based communication libraries and integrate
your protocols. The Java bundle mechanism can also be used in an Android environment. A Java bundle
developer only needs to take care about the mapping between the OIC resource representation and the
integrated technology. The required interfaces to create a Java bundle can be found in the resource-
container/bundle-java-api directory. The API consists of a set of interfaces and abstract classes. Most
important is the BaseActivator class, which has to be extended by a bundle provider. It offers the
methods for retrieving configuration parameters and for resource registration. The second important
abstract class is the BundleResource. A developer has to extend this class for concrete resource types
and implement the mapping for reads and writes on the resource attributes.
Bundle API
First step is to build the Java Bundle API.
resource-container/bundle-java-api> mvn compile
resource-container/bundle-java-api> mvn install
This compiles the bundle api and installs it in the local maven repository. All bundle projects can use the
library then.
A project can include declare a dependency on the Java bundle API. An example pom.xml can be found
in the resource-container/examples/HueJavaSampleBundle folder.
Java resource bundle
To build a Java bundle all dependencies need to be included. In order to package all dependencies the
assembly plugin is used.
maven.apache.org
<bundle>
<id>oic.bundle.hueSample</id>
<path>libHueBundle.so</path>
<activator>huesample</activator>
<version>1.0.0</version>
<resources>
<resourceInfo>
<name>light</name>
<resourceType>oic.r.light</resourceType>
<address>http://192.168.0.2/api/newdeveloper/lights/1</address>
</resourceInfo>
</resources>
</bundle>
The resource container starts. Follow the instructions and press [ENTER] to see the demonstration of
how bundles get loaded, stopped, activated and the whole container gets stopped.
After the container is started you can execute in parallel the ContainerClientSample, which executes the
test requests against container provided resources.
To execute the ContainerSampleClient run:
~/[release-folder]/service/resource-container/ $ ./ContainerSampleClient
5.2.2 Tizen
This sections covers the Tizen Sample Applications of Resource Container module.
5.2.2.1 Working Flow
This section describes the working flow of the ContainerClientApp and ContainerServerApp Tizen
Applications.
ContainerServerApp show the functionalities provided by Resource Container module.
ContainerClientApp is to discover the resource created by ContainerServerApp.
5.2.2.2 Build and Import Procedure
Import ContainerServerApp and ContainerClientApp applications from the given path :
service\resource-container\examples\tizen to Tizen IDE.
To import projects in tizen IDE, Go to File -> Import -> Tizen -> Tizen Native Projects.
Create a lib folder in ContainerClientApp and ContainerServerApp projects (if not present) and
copy the required libraries (mentioned below) extracted from the generated RPM package as
shown in section 3.3
Required libraries for ContainerServerApp and ContainerClientApp are liboc.so,
liboctbstack.so, libuuid.so, liboc_logger.so, liboc_logger_core.so, libconnectivity_abstraction.so,
librcs_client.so, librcs_common.so, librcs_container.so, librcs_server.so, libboost_date_time,
libboost_system and libboost_thread.
Additional libraries required for ContainerServerApp are : libHueBundle.so,
libDISensorBundle.so and libBMISensorBundle.so. These libraries also should be added in the lib
folder.
Specify the path of the unzipped boost libraries in ContainerServerApp and ContainerClientApp
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.
Clean and build ContainerServerApp and ContainerClientApp projects and launch the
applications in Tizen 2.3 device.
5.2.2.2.1 Running Applications
Running the ContainerServerApp provides two options on the home screen :
Start Container
Stop Container
On selecting the start container options, it trigeers the container to start with default bundle provided in
the configuration file. Once the container has started successfully the remaining container option is
displayed to test the resource container APIs. The following images show the homescreen of the
application and screen for container APIs.
Note : In sample application we have the configuration file (.xml) with hue bundle.
The remaing container APIs can be tested now as the container has been successfully started. On
selecting the first option i.e. List Bundles, it displayes the list of all bundles in the container.
On selecting the option for List Hue resources, it displayes all resources added to the Hue bundle. Since
we have not added amy resources it displayes the resource bundle size as 0.
Using the Add HUE Bundle Resource option, light resources can be added to the HUE bundle. On
selecting this option a new resource is created and added. The following logs will be displayed :
The created resources that have been added to Hue bundle can be deleted using the Remove HUE
Bundle Resource. Multiple resources can be created and added and deleted.
Hue Bundle is added and started by default on starting the container. Addition bundles can also be
added to the container. These APIs can be tested using the add and start bundle options.
Add BMI bundle and Start BMI bundle options in the applications add a BMISensorBundle to the
already started resource container. On selecting the Add BMI bundle option first and then Start BMI
bundle option, BMISensor bundle is added to the container. Following logs are shown :
We can verify the authenticity by checking the list of bundles of the container. This can be done using
the first option List Bundles. The following logs is displayed :
Here we can see the bundle list size has increased and BMISensor bundle has been added to the
container. Now similarly to stop and remove a bundle from the container, stop bundle and remove
bundle options can be used. The Stop BMI Bundle and Remove BMI Bundle options will stop and
remove the BMISensor bundle if added to the container . The following logs will be displayed :
The container can be stopped using the stop container button on the top right hand corner of the screen.
Selecting this button automatically removes all bundles added to the container and stops the container.
If the container is not yet started then this button has no effect what so ever.
Running the ContainerClientApp provides only one option to start the container client. On selecting the
start container client option new menu is shown. The homescreen is shown below.
If Resources have been created by the ContainerServiceApp, is can be discovered by this application. If a
light resource discovery is to be made, selet the Start light resource Discovery option to begin the
discovery request. If the a light resource is running in the same network it will get a callback :
Once the desired resource has been found, the discovery request can be terminated by selecting the
Stop Discovery option. Once the discovery has been canceled, we will get a list of all the resources
discovered to select from for our use. Similarly discovery can be made for a soft sensor resource also.
5.2.3 Android
This sections covers the Android Sample Applications of Resource Container module.
<Experimental Support >
Resource container for Android platform is not supported officially. It is under development,
5.2.3.1 Working Flow
This section describes the working flow of the RCSampleClientApp and RCSampleServerApp Android
Applications.
RCSampleServerApp show the functionalities provided by Resource Container module.
RCSampleClientApp is to discover the resource created by RCSampleServerApp.
(b) Create libs folder in app folder each of RCSampleClientApp and RCSampleServerApp projects (if
not present) and copy the required libraries.
-
iotivity-{TARGET_ARCH}-base-{MODE}.aar located in
{Iotivity_root} /android/android_api/base/build/outputs/aar
iotivity-{TARGET_ARCH}-service-{MODE}.aar located in
{Iotivity_root} /service/resource-encapsulation/android/service/build/outputs/aar
iotivity-{TARGET_ARCH}-resource-container-{MODE}.aar located in
{Iotivity_root} /service/resource-container/android/service/build/outputs/aar
libBMISensorBundle.so
libDISensorBundle.so
From : {Iotivity_root}/out/android/{TARGET_ARCH}/{MODE}/
where TARGET_ARCH is a build option for scons of iotivity and where MODE is release or debug.
(d) Clean and build RCSampleClientApp and RCSampleServerApp projects and launch the applications.
Note : In sample application we have the configuration file (.xml) with one bundle.
It will create a resource of type oic.sensor. To discover the resource press DISCOVER RESOURCE
button on RCSampleClientApp. The following logs will be shown on the Client app:
User can press the option 3,4,5 to List, add, remove resources from the bundle. Same as done for
Discomfort Index sensor.
When a resource is added to BMI bundle it can be discovered from the RCSampleClientApp by pressing
Discover Resource Button.
Press option 6 Stop Bundleto stop the Bundle. If user stops the bundle all the resources that are
added to bundle will be removed. Press option 7 Remove Bundle to remove the BMI bundle.
6 THINGS MANAGER
Things Manager is operated in the IoTivity Base messaging environment as shown in the Figure below.
There are two kind of usages in the Things Manager; SDK API and Raw API usage
For the first usage, Things Manager provides SDK API described in the previous section which hides the
details of IoTivity functions and protocols and provides a simple operation set in C++.
The raw API also can be used to use main function of group management (i.e. group action) and other
functionalities of group management can be emulated by using raw API. The raw API introduces
Resource based concept and matched with CoAPs basic functionalities (i.e. GET/PUT/POST/DELETE).
This API now provided as a simple operation set in C language.
Things Manager comprises 3 components from the perspective of functionality: Group Manager and
Things Configuration/Maintenance.
-
Group Manager APIs provide functions for application to find appropriate devices (i.e. things) in
network, create a group of the devices, check a presence of member devices in the group, and
actuate a group action in a more convenient way.
Things Configuration APIs have two main usages: (1) On a server side, bootstrapping requisite
information (i.e. system configuration parameters) from a bootstrap server to access other IoT
services, (2) On a client side, getting/updating the system configuration parameters from/to
multiple remote things.
Things Maintenance APIs have two functionalities: 1) FactoryReset to restore all configuration
parameters to default one, and (2) Reboot to request a system rebooting.
Resource models used for Things Configuration and Maintenance function are standardized in OIC
specification document and specified as follows:
Resource Name
URI
Resource Type
Configuration
/oic/con
oic.wk.con
Attribute
Name(key)
Value
Type
Access
Modes
String
R, W
Location
loc
Json
R, W
Location Name
locn
String
R, W
Currency
String
R, W
Region
String
R, W
Attribute
Device Name
Description
Human friendly name
e.g., Bobs Thermostat
Resource Name
URI
Resource Type
Maintenance
/oic/mnt
oic.wk.mnt
Attribute
Attribute
Name(key)
Value
Type
Access
Modes
Description
0 No action (Default)
Factory_Reset
fr
boolean
R,W
Reboot
rb
boolean
R,W
StartStatCollection
ssc
boolean
R,W
Linux
6.1.1.1
Figure 11: Example Scenario for Testing Group Formation / Action Feature
-
There are mainly two entities composing Bulb Control System: one mobile phone and two
bulbs. This scenario shows that users can easily manage their at-home light bulbs with their
mobile phone. One of convincing situations for the scenario is the moment that users leave
home for work; they may want to turn all bulbs at home off with their phone.
At initial stage, we assume that two bulbs are already on.
After an application to control the bulbs executed on the phone, , the phone discovers the
bulbs around itself and sets them as Group for Bulb Control Service.
After Group made, user can see a switch to control.
Once clicking the switch to off, the bulbs are going to turning off.
-
6.1.1.2
Working Flow
[Example Topology]
This section introduces an experimental example of the scenarios run on Ubuntu platform. This
section describes how Things (i.e. bulbs and bookmark) can make group communication and
what kind of features can be provided by Things Manager, specifically Group Manager.
Run all light bulb applications and a bookmark application
First of all, users execute light bulb applications corresponding to actuators (called
resources from here). Create the Ubuntu device topology according to Example Topology
and run executables
To execute all bulb applications, enter as follows:
~/deviceB/service/things-manager/build/linux/release$ ./lightserver
Resource URI : /a/light
Resource Type Name : core.light
Resource Interface : oc.mi.def
Resource creation is successful with resource handle : 0x1dd1de0
~/deviceC/service/things-manager/build/linux/release$ ./lightserver
As seeing above, users can know details of the registration for the bulb resource including
resource URI, resource type.
Lastly, users execute a user application, called a groupserver. Once the application is
executed, it initially creates a group resource with a resource type, a.collection, and
attempts to discover all candidate resources in a network. In this example, the candidate
resource is a light bulb resource with a resource type core.light. After a few seconds (e.g.,
5 seconds), the application binds the found light bulb resource into the group resource,
which is a creation of the group. If the creation is successful, users can see a menu to ask
users input.
To run the application, enter as follows:
~/deviceA/service/things-manager/build/linux/release $ ./groupserver
DISCOVERED Resource:
URI of the resource: /a/light
Host address of the resource: coap://10.251.42.143:45631
List of resource types:
core.light
core.brightlight
List of resource interfaces:
oc.mi.def
oc.mi.ll
1 :: CREATE ACTIONSET
2 :: EXECUTE ACTIONSET(ALLBULBON)
3 :: EXECUTE ACTIONSET(ALLBULBOFF)
4 :: CREATE ACTIONSET(R_ALLBULBON)
41 :: EXECUTE ACTIONSET 42 :: CANCEL ACTIONSET
5 :: CREATE ACTIONSET(S_ALLBULBON)
51 :: EXECUTE ACTIONSET 52 :: CANCEL ACTIONSET
6 :: GET ACTIONSET
7 :: DELETE ACTIONSET
8 :: QUIT
9 :: FIND GROUP
0 :: FIND BOOKMARK TO OBSERVE
_(prompt)
In the step , groupserver application creates a group resource. Then, to request this
resource with GET or PUT, users need to find the group resource using findResource()
function.
To do this, just enter a digit 9 as follows:
~/deviceA/service/things-manager/build/linux/release $ ./groupserver
1 :: CREATE ACTIONSET
2 :: EXECUTE ACTIONSET(ALLBULBON)
3 :: EXECUTE ACTIONSET(ALLBULBOFF)
4 :: CREATE ACTIONSET(R_ALLBULBON)
41 :: EXECUTE ACTIONSET 42 :: CANCEL ACTIONSET
5 :: CREATE ACTIONSET(S_ALLBULBON)
51 :: EXECUTE ACTIONSET 52 :: CANCEL ACTIONSET
6 :: GET ACTIONSET
7 :: DELETE ACTIONSET
8 :: QUIT
9 :: FIND GROUP
0 :: FIND BOOKMARK TO OBSERVE
9(prompt)
The next step is to define group action sets for the group. In this example, there are two
predefined group action sets: AllBulbsOn and AllBulbsOff.
~/deviceA/service/things-manager/sampleapp/linux/groupaction/groupserver.cpp
void createActionSet_AllBulbOff()
{
ActionSet *allBulbOff = new ActionSet();
allBulbOff->actionsetName = "AllBulbOff";
action->listOfCapability.push_back(capa);
allBulbOff->listOfAction.push_back(action);
}
if (g_resource)
{
thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
First, a name of group action set is specified in actionsetName variable of ActionSet instance.
Next, for each light bulb resource, users need to create an Action class instance and specify
the light bulb resources URI in target variable of Action instance. And another class instance,
called Capability, is needed to be created to specify an attribute key and value of the target
resource. The attribute key and value are written in capability and status variables of
Capability instance class, respectively. After filling the Capability instance, store it to
listOfCapability vector variable of Action instance and store the Action instance to
listOfAction vector variable of ActionSet instance.
On the ActionSet instance for AllBulbsOff is specified, users just use addActionSet()
function provided in ThingsManager class.
To execute two group action sets to turn off/on all bulbs, enter a digit 1. If the creation is
successful, users can see the below log message:
1(prompt)
onPut
Result is OK.(for ALLBULBON)
onPut
Result is OK. (for ALLBULBOFF)
~/deviceA/service/things-manager/sampleapp/linux/groupaction/groupserver.cpp
void allBulbOff()
{
g_ thingsMgr->executeActionSet(resource, AllBulbOff, callback)
}
To execute a group action set to turn off all bulbs, enter a digit 3 as follows:
In execution of ./groupserver on deviceA
1 :: CREATE ACTIONSET
2 :: EXECUTE ACTIONSET(ALLBULBON)
3 :: EXECUTE ACTIONSET(ALLBULBOFF)
3(prompt)
Then, users can notice that all light bulb applications have a Off event as follows:
If the bookmark resource is found and the request is successful, users can see a log message
like the above. At the same time, users can also notice that the bookmark application has a
new prompt to get users input as follows:
In execution of ./bookmark on deviceD
If users want to change a status of the bookmark resource, simply put a digit 0 or 5 as
follows:
In execution of ./bookmark on deviceD
Once the status changes, the bookmark application sends the notification to the groupserver
application. If the notification informs that a book is opened, just execute an AllBulbOn
action set and send a request for light bulb resource to turn on.
After that, users can notice that all light bulb applications have a On event as follows:
In execution of ./lightserver on deviceB and deviceC
Along with an ordinary group action, Group Manager provides time-related group actions like
scheduled and recursive group action. The scheduled group action can be utilized for an
execution of group action after a certain time delay. For example, it can be used where users
wants to execute a group action after 10 seconds. The other, recursive group action, can be
utilized for an repeated execution of group action every a certain time. For example, it can be
used where users wants to execute a group action at 1 PM every day.
For creating these group actions, users should specify a type of group action in creation. All
supported types for group action includes NONE, SCHEDULED, and RECURSIVE. And users
should also specify a time parameter of a time delay and an time interval used for scheduled
and recursive group action, respectively. The below is an example for creating recursive group
action. Creating a scheduled group action does not make much of difference with this.
~/deviceA/service/things-manager/sampleapp/linux/groupaction/groupserver.cpp
void createRecursiveActionSet_AllBulbOn()
{
string actionsetDesc;
ActionSet *allBulbOn = new ActionSet();
allBulbOn->actionsetName = "AllBulbOnRecursiveCall";
allBulbOn->type = OIC::ACTIONSET_TYPE::RECURSIVE;
allBulbOn->setDelay(5);
//every 5 seconds
action->listOfCapability.push_back(capa);
allBulbOn->listOfAction.push_back(action);
}
if (g_resource)
{
thingsMgr->addActionSet(g_resource, allBulbOn, onPut);
}
1 :: CREATE ACTIONSET
2 :: EXECUTE ACTIONSET(ALLBULBON)
3 :: EXECUTE ACTIONSET(ALLBULBOFF)
4 :: CREATE ACTIONSET(R_ALLBULBON)
41 :: EXECUTE ACTIONSET 42 :: CANCEL ACTIONSET
5 :: CREATE ACTIONSET(S_ALLBULBON)
51 :: EXECUTE ACTIONSET 52 :: CANCEL ACTIONSET
4(prompt)
onPut
Result is OK. (for recursive group action)
1 :: CREATE ACTIONSET
2 :: EXECUTE ACTIONSET(ALLBULBON)
3 :: EXECUTE ACTIONSET(ALLBULBOFF)
4 :: CREATE ACTIONSET(R_ALLBULBON)
41 :: EXECUTE ACTIONSET 42 :: CANCEL ACTIONSET
5 :: CREATE ACTIONSET(S_ALLBULBON)
51 :: EXECUTE ACTIONSET 52 :: CANCEL ACTIONSET
41(prompt)
Then, users can see the log message every 5 seconds as below
In execution of ./lightserver on deviceB and deviceC
When users want to stop the recursive group action still running, just call a cancelActionSet()
function.
~/deviceA/service/things-manager/sampleapp/linux/groupaction/groupserver.cpp
void CancelRecursive_allBulbOn()
{
groupMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
}
1 :: CREATE ACTIONSET
2 :: EXECUTE ACTIONSET(ALLBULBON)
3 :: EXECUTE ACTIONSET(ALLBULBOFF)
4 :: CREATE ACTIONSET(R_ALLBULBON)
41 :: EXECUTE ACTIONSET 42 :: CANCEL ACTIONSET
5 :: CREATE ACTIONSET(S_ALLBULBON)
51 :: EXECUTE ACTIONSET 52 :: CANCEL ACTIONSET
42(prompt)
Then, users can see no more log message at light resource applications.
6.1.1.3
This scenario shows two requests from an administrator to things: First is a factory reset and
second is a system reboot. A factory reset is to restore all system configuration parameters to
default one. And a system reboot is just to let the system reboot.
6.1.1.4
Working Flow
[Example Topology]
Note that this section introduces an experimental example of the scenarios run on Ubuntu
platform.
Run all relevant applications: a bootstrapserver, two con-servers, and con-client applications.
First of all, users execute all relevant applications. A bootstrapserver application represents a
bootstrap server, a con-server application does a Thing, and a con-client application does an
administrator. Create the Ubuntu device topology according to Example Topology and run
executables
To execute the applications, enter as follows:
~/deviceA/service/things-manager/build/linux/release$ ./bootstrapserver
~/deviceB/service/things-manager/build/linux/release$ ./con-server
~/deviceC/service/things-manager/build/linux/release$ ./con-server
(0) Quit
(1) Bootstrap
(2) Create Configuration Resources
~/deviceD/service/things-manager/build/linux/release$ ./con-client
(0) Quit
(1) Find all resources(URI: /oic/con, /oic/mnt, /factoryset)
(2) Find all groups
(3) Get a Configuration resource
(4) Update a device name attribute value
(5) FactoryReset (for the group)
(6) Reboot (for the group)
(10) Show Configuration Units
g_thingsmanager->doBootstrap(&onBootstrap);
this release, users should manually retrieve these configuration parameters. This process is
shown as following code:
~/deviceA/service/things-manager/sampleapp/linux/configuration/con-server.cpp
void onBootstrap(const HeaderOptions& headerOptions, const OCRepresentation& rep, const
int eCode)
{
if (eCode == SUCCESS_RESPONSE){
std::cout << "\n\nGET request was successful" << std::endl;
std::cout << "\tResource URI: " << rep.getUri() << std::endl;
defaultDeviceName = rep.getValue< std::string >("n");
defaultLocation = rep.getValue< std::string >("loc");
defaultLocationName = rep.getValue< std::string >("locn");
defaultRegion = rep.getValue< std::string >("r");
defaultCurrency = rep.getValue< std::string >("c");
Based on the codes, users can execute the con-server application to bootstrap by entering a
digit 1 as follows:
In execution of ./con-server on deviceB and deviceC
(0) Quit
(1) Bootstrap
(2) Create Configuration/Maintenance Resources
1
Finding Bootstrap Server resource...
DISCOVERED Resource:
URI of the resource: /bootstrap
Host address of the resource: coap://10.251.42.143:33472
List of resource types:
bootstrap
List of resource interfaces:
oc.mi.def
Getting bootstrap server representation on: oc.mi.def
(0) Quit
(1) Bootstrap
(2) Create Configuration/Maintenance Resources
2
Configuration Resource is Created!(URI: /oic/con)
Maintenance Resource is Created!
Factoryset Resource is Created!
(0) Quit
(1) Find all resources(URI: /oic/con, /oic/mnt, /factoryset)
(2) Find all groups
1
Finding Configuration Resource...
Finding Maintenance Resource...
DISCOVERED Resource:
URI of the resource: /oic/mnt
Host address of the resource: coap://10.251.42.143:53773
List of resource types:
oic.wk.mnt
List of resource interfaces:
oc.mi.def
oc.mi.b
oc.mi.ll
DISCOVERED Resource:
URI of the resource: /oic/con
Host address of the resource: coap://10.251.42.143:53773
List of resource types:
oic.wk.con
List of resource interfaces:
oc.mi.def
oc.mi.b
oc.mi.ll
(The other Configuration/Maintenance Resources are found)
Note that a group can be represented to a collection resource. Thus, users need to find the
collection resources as to find groups. To do this, enter a digit 2 as follows:
In execution of ./con-client on deviceD
(0) Quit
(1) Find all resources(URI: /oic/con, /oic/mnt, /factoryset)
(2) Find all groups
~/deviceA/service/things-manager/sampleapp/linux/configuration/con-client.cpp
ConfigurationName name = "n";
ConfigurationValue value = "OIC Device";
if (g_thingsmanager->updateConfigurations(g_configurationCollection,
configurations,&onUpdate) != OC_STACK_ERROR)
isWaiting = 1;
Based on the above code, to update a value of Configuration resource, enter a digit 4 as
follows:
In execution of ./con-client on deviceD
(0) Quit
(1) Find all resources(URI: /oic/con, /oic/mnt, /factoryset)
(2) Find all groups
(3) Get a Configuration resource
(4) Update a device name attribute value
Then, users can notice that all con-server applications have received a request to update the
value as follows:
~/deviceA/service/things-manager/sampleapp/linux/configuration/con-client.cpp
ConfigurationName name = "all";
std::cout << "For example, get configuration collection's value" << std::endl;
if (g_thingsmanager->getConfigurations(g_configurationResource, configurations,
&onGet)!= OC_STACK_ERROR)
isWaiting = 1;
One functionality of Thing Maintenance is a factory reset to restore all system configuration
parameters to default one. As described in Section 5.2, all default parameters are stored in
Factoryset resource.
For a factory reset functionality, users need to just update a value of FactoryReset resource
to true. After the value is updated to true, the con-server application checks the value
and executes a factory reset by itself. The logic how to do a factor reset is not provided by
Things Maintenance. This con-server application just shows one of example to do a factory
reset using with Factoryset resource. Please refer to the con-server application for this.
To sum up, users need to just update a value of FactoryReset resource by using factoryReset()
function. The code of this procedure is shown as follows:
~/deviceA/service/things-manager/sampleapp/linux/configuration/con-client.cpp
// factory reset
if (g_thingsmanager->factoryReset(g_maintenanceCollection, &onFactoryReset)
!= OC_STACK_ERROR)
isWaiting = 1;
Based on the code, to request a factory reset to all con-server applications, enter a digit 5
as follows:
In execution of ./con-client on deviceD
(0) Quit
...
(5) FactoryReset (for the group)
(6) Reboot (for the group)
(10) Show Configuration Units
Then, users can notice that all con-server applications have received a request to do a factory
reset as follows:
In execution of ./con-server on deviceB and deviceC
Based on the code, to update a value of Reboot resource, enter a digit 6 as follows:
In execution of ./con-client on deviceD
(0) Quit
...
(5) FactoryReset (for the group)
(6) Reboot (for the group)
(10) Show Configuration Units
Then, users can notice that all con-server applications have received a request to reboot a
system as follows:
In execution of ./con-server on deviceB and deviceC
Please note that an actual system reboot can happen when users run the application as a
super user.
6.1.2
Tizen
First of all, users execute light bulb applications (linux) corresponding to actuators (called resources from
here).
To execute the light bulb application, enter as follows:
~/out/linux/<arch>/release/service/things-manager/SampleApp/linux $ ./lightserver
Resource URI : /a/light
Resource Type Name : core.light
Resource Interface : oc.mi.def
Resource creation is successful with resource handle : 0x1dd1de0
As seeing above, users can know details of the registration for the light bulb resource including resource
URI, resource type, and resource interface.
Next, execute a bookmark application. To do, enter as follows:
~/out/linux/<arch>/release/service/things-manager/SampleApp/linux $ ./bookmark
Resource URI : /core/bookmark
6.1.2.2.2
Now, users execute Tizen application, called a TM sample app. Once the application is executed, it
shows two options: GROUP APIS & CONFIGURATION APIS.
Once you select the first option the below screen will be shown:
If light resource (linux) is running, then resource information will be displayed as shown in the below
screenshot
6.1.2.2.3
The next step is to define group actionsets for the group. In this example, there are two predefined
group actionsets: AllBulbsOn and AllBulbsOff
To create action set AllBulbsOn & ALLBULBOFF click 1st option in the app
6.1.2.2.4
Now, users can notice that all light bulb applications have an On event as follows:
In execution of ./lightserver
Now, users can notice that all light bulb applications have an Off event as follows:
In execution of ./lightserver
6.1.2.2.5
User can create an action set that can be triggered recursively. In sample application we are giving time
duration of 5 seconds .
To create a recursive action set ALLBULBON click 4th option in the app.
To execute the recursive action set ALLBULBON click on th 4.1 option in the App.
Now, users can notice that all light bulb applications have an On event after each 5 seconds as follows:
(until user cancel it by clicking 4.2 option in the app)
In execution of ./lightserver
To cancel the recursive action set ALLBULBON click on the 4.2 option in the App. It will stop the
recursive action set ALLBULBON.
6.1.2.2.6
User can create an action set that can be triggered at the given date and time.
To create a scheduled action set ALLBULBOFF click on the 5th option in the app.
On clicking the 5th option the following pop-up will be shown:
To execute scheduled action set ALLBULBOFF click on the 5.1 option in the App.
To cancel the scheduled action set AllBulbsOFF click on the 5.2 option in the App. It will cancel the
scheduled action set that has been executed using 5.1 option.
6.1.2.2.7
GetActionSet (ALLBULBOFF)
To get an actionset ALLBULBOFF that we have created using 1st option of the UI.
6.1.2.2.8
DeleteActionSet (ALLBULBOFF)
To delete an action set ALLBULBOFF that we have created earlier using 1st option of the UI.
6.1.2.2.9
For the second scenario the TM sample app needs to monitor how a bookmarks status changes. To do
this, the TM sample app utilizes an observe option of CoAP specification.
To request an observe, click on the 8th option i.e. Find Bookmark to Observe. Then the TM sample
app discovers a bookmark resource in a network and then sends an observe request to the found
resource server.
If the observe request is successfully delivered to a bookmark resource server, users can see the below
prompt.
In execution of ./bookmark
Once the status changes, the bookmark application sends the notification to the groupserver application.
If the notification informs that a book is opened, just execute an AllBulbOn action set and send a
request for light bulb resource to turn on.
After that, users can notice that all light bulb applications have an On event as follows:
In execution of ./lightserver
Working Flow
This section introduces an experimental example of the scenarios run on Ubuntu platform & Tizen App.
6.1.2.4.1
6.1.2.4.2
doBootStrap
This API is used by resource server, to receive configuration information from an available bootstrap
server to configure it to access other IoT services. We receive configuration information in
onBootStrapCallback, we are updating same information to UI as shown in the below figure.
6.1.2.4.3
Create configuration resources with the retrieved configuration parameters from a bootstrap server.
Configuration Resource
Maintenance Resource
Factoryset Resource
After successful creation of all the resources the UI will be updated as shown below:
we can test the Configuration APIs of Things Configuration and Maintenance class by running our TM
sample app that has con-client in it i.e. CONFIGURATION APIS.
CONFIGURATION APIS: Click on this menu to test Things configuration and Maintenance APIs.
CONFIGURATION APIS SCREEN:
6.1.2.4.4
6.1.2.4.5
Search for the resources of the type oic.wk.con, oic.wk.mnt and factoryset using API
findCandidateResources.
6.1.2.4.6
Get configuration table from oic.wk.con resource. We will get four attributes of configuration
resource : Location, System Time, Currency and Region as shown in below screenshot.
6.1.2.4.7
For Example:
Now, if user clicks on the 3rd option Get a Configuration Resource, user will see the region attributes
has been set to the new value given by him.
6.1.2.4.8
Factory Reset
Invoke factoryReset on oic.wk.mnt resource to restore all system configuration parameters to default
one.
Note that now, If you press Get Configuration (region) option, you can see that its been reset to default
value:
6.1.2.4.9
Reboot
6.1.3
Android
First of all, users execute light bulb applications (linux) corresponding to actuators (called resources from
here).
~/out/linux/<arch>/release/service/things-manager/SampleApp/linux $ ./lightserver
Resource URI : /a/light
Resource Type Name : core.light
Resource Interface : oc.mi.def
Resource creation is successful with resource handle : 0x1dd1de0
As seeing above, users can know details of the registration for the light bulb resource including resource
URI, resource type, and resource interface.
Next, execute a bookmark application. To do, enter as follows:
~/out/linux/<arch>/release/service/things-manager/SampleApp/linux $ ./bookmark
Resource URI : /core/bookmark
6.1.3.2.2
Now, users execute Android application, called a TM sample app. Once the application is executed, it
shows two options:
GROUP APIS
CONFIGURATION APIS.
Once you select the first option the below screen will be shown:
If resource is running in background, then resource information will be displayed as shown in the
below screenshot
6.1.3.2.3
The next step is to define group action sets for the group. In this example, there are two
predefined group action sets: AllBulbsOn and AllBulbsOff. To create action set AllBulbsOn &
ALLBULBOFF click on the 1st option in the app
6.1.3.2.4
To execute action set AllBulbsOn, click on the 2nd option in the App.
After that, users can notice that all light bulb applications have an On event as follows:
In execution of ./lightserver
To execute action set AllBulbsOff, click on the 3rd option in the App.
Then, users can notice that all light bulb applications have an Off event as follows:
In execution of ./lightserver
6.1.3.2.5
User can create an action set that can be triggered recursively.In sample application we are giving
time duration of 5 seconds .
To create a recursive action set ALLBULBON click on the 4th option in the app.
To execute the recursive action set ALLBULBON click on the 4.1 option in the App.
Then users can notice that all light bulb applications have an On event after each 5 seconds as
follows: (until user cancel it by clicking 4.2 option in the app)
In execution of ./lightserver
To cancel the recursive action set ALLBULBON click on the 4.2 option in the App. It will stop the
recursive action set ALLBULBON.
6.1.3.2.6
User can create an action set that can be triggered at the given date and time. To create a
scheduled action set ALLBULBOFF click on the 5th option in the app.
On clicking the 5th option the following dialog will be shown:
To execute scheduled action set ALLBULBOFF click on the 5.1 option in the App.
To cancel the scheduled action set AllBulbsOFF click on the 5.2 option in the App. It will cancel
the scheduled action set that has been executed using 5.1 option.
6.1.3.2.7
GetActionSet (ALLBULBOFF)
To get an actionset ALLBULBOFF that we have created using 1st option of the UI.
6.1.3.2.8
DeleteActionSet (ALLBULBOFF)
To delete an action set ALLBULBOFF that we have created earlier using 1st option of the UI.
6.1.3.2.9
For the second scenario mentioned in Section7.1, the TM sample app needs to monitor how a
bookmarks status changes. To do this, the TM sample app utilizes an observe option of CoAP
specification. To request an observe, click on the 8th option i.e. Find Bookmark to Observe.
Then the TM sample app discovers a bookmark resource in a network and then sends an
observe request to the found resource server.
If the observe request is successfully delivered to a bookmark resource server, users can see the
below prompt.
In execution of ./bookmark
In execution of ./bookmark
Once the status changes, the bookmark application sends the notification to the groupserver
application. If the notification informs that a book is opened, just execute an AllBulbOn
action set and send a request for light bulb resource to turn on.
After that, users can notice that all light bulb applications have an On event as follows:
In execution of ./lightserver
6.1.3.4.1
First of all, users execute all relevant applications. A bootstrapserver application represents a
bootstrap server, a con-server application does a Thing, and a TM sample application does an
administrator.
To execute the applications, enter as follows:
~/deviceA/service/things-manager/build/linux/release$ ./bootstrapserver
6.1.3.4.2
doBootStrap :
This API is used by resource server, to receive configuration information from an available
bootstrap server to configure it to access other IoT services. We receive configuration
information in onBootStrapCallback, we are updating same information to UI as shown in the
below figure.
6.1.3.4.3
Create
server.
After successful creation of all the resources the UI will be updated as shown below
we can test the Configuration APIs of Things Configuration and Maintenance by running our
sample app that has con-client in it i.e. CONFIGURATION APIS. Now, Run the TM sample app
MAIN MENU SCREEN:
CONFIGURATION APIS: Click on this menu to test Things configuration and Maintenance APIs
6.1.3.4.4
6.1.3.4.5
Search for the resources of the type oic.wk.con, oic.wk.mnt and factoryset using API
findCandidateResources.
6.1.3.4.6
Get configuration table from oic.wk.con resource. We will get four attributes of configuration
resource : Location, System Time, Currency and Region as shown in below screenshot.
6.1.3.4.7
For example :
Now, if user clicks on the 3rd option Get a Configuration resource, user will see the region
attributes has been set to the new value given by him.
6.1.3.4.8
Factory Reset
Note that now, If you press Get Configuration (region) option, you can see that its been reset to
default value:
6.1.3.4.9
Reboot
7 RESOURCE HOSTING
The goal of Resource Hosting is to off-load the request handling works from the resource server where
original resource is located.
Resource Hosting has three functional blocks over the Resource Encapsulation Layer. Resource
Virtualization creates and registers the mirrored resources which reflects the status of the origin
resource server. The resources between origin server and mirrored resource are synchronized via
Resource Synchronization block and remote requests from resource clients are handled by the Remote
Request Handler.
Figure 13 illustrates the Deployment View of the Resource Hosting. It provides Resource Hosting APIs
that can be used to start and stop Hosting. When origin server creates a resource which is needed to
be hosted, and Hosting service in network is available, Resource Hosting makes mirrored resource of
origin server. Mirrored resource maintains data synchronized with origin resource. If client get data or
discovery resource by information of origin resource, Mirrored resource will responds to client instead
of origin server. When data of origin resource updated, Data of mirrored resource is cloned from origin
resource and mirrored resource notify to clients.
Tizen
Pre-requisite
Run sampleprovider, Linux applications to test the Hosting APIS.
After launching the Tizen application (RHSampleApp), run sampleconsumer, Linux
applications for complete two way testing.
<iotivity>/out/linux/<arch>/release/service/notification-manager/SampleApp/linux
$./sampleprovider
App description
Above given is the home screen of the application. Platform configurations will be done
on the launch of the application by default.
On clicking the Find and Host button, the notification manager service will start
completely.
Stop button will terminate the notification manager service completely. Once the service
is terminated it can be restarted using the Find and Host button on the same screen.
Once user presses Find and Host button the corresponding logs can be seen on linux and tizen
Applications.
Sampleprovider (Linux)
RHSampleApp (Tizen)
<iotivity>/out/linux/<arch>/release/service/notification-manager/SampleApp/linux$./sampleconsumer
Now, if user enter 1 in sampleconsumer Application, it will send a observer request to RHSampleApp(as
7.1.3 Android
There are three Android applications which needs to be run to test the functionality of Hosting Manager.
a. SampleProviderApp
b. SampleResourceHosting
c. SampleConsumer
SampleProviderApp acts as TemperatureHumidity Sensor
ResourceHosing will host the SampleProviderApp.
SampleConsumer is the one that will perform operations (GET, PUT, DELETE) on the hosted resource.
Note: As ResourceHosting is hosting the resource all the requests from SampleConsumer App will come
to SampleResourceHosting App.
Internet of Things scenario:
We can consider SampleProviderApp as a thin device and SampleResourceHosting as a powerful device,
which can host the resource running in the thin device and can handle all the request on behalf of thin
device.
8.1.3.1 Working flow
First, run the SampleProviderApp application
Note: Logs in the SampleProviderApp may take some time to update. Just wait for few seconds.
Once logs updated you can start SampleConsumer to perform operation on the resource that is hosted
by SampleResourceHosting.
When user starts the SampleConsumer App the following window will be shown:
7.1.3.1.1
Get Request
If user presses GET button it will send request to SampleResoureHosting app to get current
temperature and humidity. Once it got the response the logs will be updated as shown below:
As SampleConsumer is already observing resource so any change on the resource, will notify the
SampleConsumer.
Following logs will be shown in SampleConsumer:
Similarly, if user presses UP *Humidity+ button in SampleProviderApp it will increase the current
Humidity by 1.
The following logs will be shown SampleProviderApp
As SampleConsumer is already observing the resource so any change on the resource, will notify the
SampleConsumer.
Following logs will be shown in SampleConsumer:
Note : Security features like Device Ownership are not available in v1.0 implementation of IoTivity.
Enrollee
All devices with limited CPU, memory, and power resources, so- called "constrained devices" often used
as sensors/actuators, smart objects, or smart devices) are termed as Enrollee devices.
All the constrained devices discussed above may or may not have the user interface to take user input
and connect to the user desired networks.
8.1.2
Mediator
The purpose of a Mediator in MultiPHY Easy Setup is to enable Enrollee devices running on different
transports to be easily connected to the target network.
Mediator having support for different transports acts as a controller device to enable target
connectivity to multiple Enrollee running on different transports
8.1.3
Enroller
Enroller is the target network entity to be connected by Enrollee. Mediator provides the target Enroller
information to the Enrollee. The Mediator may get the Enroller information either from the application
user or dynamically fetch from the Enroller depending on the deployment transport and scenario.
Provisioning phase involves finding the supported Networks by the Enrollee. Table 1 provides high level
view of the sequence and the network resource usage is also shown in the sequence.
Network Resource has several attributes as shown in the Table 2
Resource Name
URI
Resource Type
Network
/oic/net
oic.net
Attribute
Current Network
Type
Attribute
Name(key)
Value Type
Access
Modes
Description
cnt
integer
Available
Network Type
ant
Array
integers
of
Provisioning phase involves finding the provisioning status of the Enrollee by the Mediator and perform
the provisioning of network information based on the provisioning status. Provisioning Resource has
several attributes as shown in the Table 2
Resource Name
URI
Resource Type
Provisioning
/oic/prov
oic.prov
Attribute
Provisioning
Status
Attribute
Name(key)
Value Type
Access
Modes
ps
integer
Description
Indicates the provisioning status of the
device
(1: Need to provision, 2: Connected to
internet)
Target NetType
tnt
integer
RW
Target NetName
tnn
string
RW
Credential
cd
string
RW
Trigger
tr
Figure 15: Mediator Application for EasySetup before/After OnBoarding and Provisioning
StartSetup will start the OnBoarding and Provisioning Process using the information provided by the
user in the UI. After the provisioning is succesful, the UI will be updated as shown in the
hosted by the Enrollee device in the network and to be controlled by the user using different client
applications.
8.5.1.2
Scons command
If the build is successful you will see enrollee.hex file generated in the following path
out/arduino/avr/debug/service/easy-setup/sampleapp/enrollee/arduino/enrollee.hex
Once OnBoarding is success, press p to start the provisioning of the Enrollee device. If the provisioning
resources are started successfully, log as shown in Figure 20 will be shown
If provisioning of network information is successful, Enrollee will try conneting to the target network
provided by the Mediator. Arduino Enrollee will show the log as shown in the figure below
Figure 21: Enrollee log after mediator provisions the target network info.