![Page 1: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/1.jpg)
Embedded Software Lab. @ SKKU
15
1
Sungkyunkwan University
Tizen/Artik IoT Practice Part 5IoTivity Simple Server and Simple Client
![Page 2: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/2.jpg)
Embedded Software Lab. @ SKKU
15
2
• In IoTivity, an entity(e.g. Sensor, Actuator) is being handled as a resource(OCF Resource Model).– Each resource contains resource and device types, CRUDN
Operations, URI information– Users can access the Resource via URI and RESTful interface
IoTivity Resource
![Page 3: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/3.jpg)
Embedded Software Lab. @ SKKU
15
3
• Simple IoTivity Server & Client– Make a simple server (Service Provider [e.g. sensors, actuators]) and simple
client (e.g. Android Application) using IoTivity base API(CRUDN).• OCF Server
– In IoTivity network topology, OCF Server handles the CRUDN requests– E.g Temperature Sensors, Lights, Humidity Sensors, Air conditional etc..
• OCF Client– In IoTivity network topology, OCF Client typically finds resources and sends
CRUDN requests – Android, Linux, Tizen, Windows, etc..
IoTivity Simple Server & Client
![Page 4: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/4.jpg)
Embedded Software Lab. @ SKKU
15
4RESTful Resource Model
CRUDN
RESTful API
• RESTful API– Http request interface such as GET, PUT, POST, DELETE
• Using RESTful API, users can control the OCF server device in remote
![Page 5: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/5.jpg)
Embedded Software Lab. @ SKKU
15
5
• Using IoTivity base API set, make a simple server (Temperature, Humidity sensors) and Android simple client App
Simple Client & Server Scenario
Temperature Sensor
URi : /a/temperatureType : core.temperatureAPI : RUND
…
CRUDN
Source Repository : https://github.com/gudbooy/IoTivity_Sample_Things.git
![Page 6: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/6.jpg)
Embedded Software Lab. @ SKKU
15
6
• Resource class contains basic operation of IoTivity & CRUDN virtual functions (interface set)
Resource Class
IoTivity/resource/examples/IoTivity_Sample_Server/resource.h File
User-defined Virtual Interface
Common Interface for Entity Handler
<User Define Virtual Function>put : Set the data sent from the clineget : Get the data requested from the ClientSensorValueRead : Sensor Acquisition Read Thread ChangeResourceRepresentation : Observe Thread Logic
<Common Interface Function>Resource Creation Logic :Resource Creation and Registering the URI resourceEntityHandler Logic : Request Handling Parsing Logic
![Page 7: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/7.jpg)
Embedded Software Lab. @ SKKU
15
7
• Common IoTivity Resource API – Resource Creation, Resource Handler (CRUDN Request Parser)
Resource Class Implementation
IoTivity/resource/examples/IoTivity_Sample_Server/resourceImpl.cpp File
Resource Creation Function
Initialization Uri & Resource Type
Registering CRUDN APIParsing Handler Callback
Resource RegisteringRequest Parsing Logic
CRUDN API Handler Unit
![Page 8: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/8.jpg)
Embedded Software Lab. @ SKKU
15
8
• Entity handler refers to the CRUDN request parsing callback function– GET : get the sensor data, then send data with response to the clients– PUT : receive the status value (e.g. Turn On, Off) from the client, and set the status – Observe : Periodically, observer thread publishing the sensor data to registered clients
Entity Handler - CRUDN Request Handler
GET
Put
Delete
Observe
![Page 9: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/9.jpg)
Embedded Software Lab. @ SKKU
15
9
• E.g., Light, Humidity, Temp
Server (Thing Device) Interface
<Temperature Things>
Things Meta-Data
URI, Resource Type
< Get Logic >
IoTivity/resource/examples/IoTivity_Sample_Server/simple_server_temp.h / .cpp File
![Page 10: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/10.jpg)
Embedded Software Lab. @ SKKU
15
10Server (Thing Device) Interface (2/2)
<Put Logic> <Observation Logic>
Get the data from the Representation
Notify the current message to observers
<Sensor Logic>Sensor Thread Creation
![Page 11: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/11.jpg)
Embedded Software Lab. @ SKKU
15
11
• IoTivityWrapper.java
Simple Client (Android)
Listener Callback
Operation
![Page 12: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/12.jpg)
Embedded Software Lab. @ SKKU
15
12findResource() - Resource Find LogicPlatform Configuration
Find Resource API
<Find Resource Listener Callback>
Found resource info
![Page 13: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/13.jpg)
Embedded Software Lab. @ SKKU
15
13GET & PUT Function
<GET Function>
<GET Listener Callback>
<PUT Function>
<Observe Function>
![Page 14: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/14.jpg)
Embedded Software Lab. @ SKKU
15
14Client Resource Description
To get the value from Representation for GET, OBSERVE
To set the value to Representation for PUT
![Page 15: Practice-05-Simple Server and Simple Client · Embedded Software Lab. @ SKKU 15 8 • Entity handler refers to the CRUDN request parsing callback function – GET : get the sensor](https://reader036.vdocuments.us/reader036/viewer/2022081523/5fd98d4aefe4bc3ad5619845/html5/thumbnails/15.jpg)
Embedded Software Lab. @ SKKU
15
15IoTivity Communication Demo
1
1
2
/a/temp - PUT Status ON
/a/humidity - PUT Status ON2
3 4
3 4
Temperature Humidity
/a/temp - Get /a/humidity - Get