Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Embedded Software Lab. @ SKKU
15
1
Sungkyunkwan University
Tizen/Artik IoT Practice Part 5IoTivity Simple Server and Simple Client
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
Embedded Software Lab. @ SKKU
15
3
• Simple IoTivity Server & Client– Using Iotivity base API (CRUDN), making a simple server (Service Provider
[e.g. sensors, actuators]) and simple client (e.g. Android Application)
• 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
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
Embedded Software Lab. @ SKKU
15
5
• Using IoTivity base API set, making 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
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
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
Embedded Software Lab. @ SKKU
15
8
• Entity Handler refers to a 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
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
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
Embedded Software Lab. @ SKKU
15
11
• IoTivityWrapper.java
Simple Client (Android)
Listener Callback
Operation
Embedded Software Lab. @ SKKU
15
12findResource() - Resource Find Logic
Platform Configuration
Find Resource API
<Find Resource Listener Callback>
Found resource info
Embedded Software Lab. @ SKKU
15
13GET & PUT Function
<GET Function>
<GET Listener Callback>
<PUT Function>
<Observe Function>
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
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