1 15
Tizen/Artik IoT Practice Part 5 IoTivity Simple Server and Simple Client
Sungkyunkwan University
Embedded Software Lab. @ SKKU IoTivity Resource 2 15
• 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
Embedded Software Lab. @ SKKU IoTivity Simple Server & Client 3 15 • 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..
Embedded Software Lab. @ SKKU RESTful Resource Model 4 15 • RESTful API – Http request interface such as GET, PUT, POST, DELETE • Using RESTful API, users can control the OCF server device in remote
RESTful API
CRUDN
Embedded Software Lab. @ SKKU Simple Client & Server Scenario 5 15 • Using IoTivity base API set, make a simple server (Temperature, Humidity sensors) and Android simple client App
Temperature Sensor CRUDN URi : /a/temperature Type : core.temperature API : RUND
…
Source Repository : https://github.com/gudbooy/IoTivity_Sample_Things.git Embedded Software Lab. @ SKKU Resource Class 6 15 • Resource class contains basic operation of IoTivity &
CRUDN virtual functions (interface set)
Common Interface for Entity Handler
Embedded Software Lab. @ SKKU Resource Class Implementation 7 15 • Common IoTivity Resource API – Resource Creation, Resource Handler (CRUDN Request Parser)
IoTivity/resource/examples/IoTivity_Sample_Server/resourceImpl.cpp File
Initialization Uri & Resource Type
Registering CRUDN API Parsing Handler Callback Resource Registering Request Parsing Logic
Resource Creation Function
CRUDN API Handler Unit
Embedded Software Lab. @ SKKU Entity Handler - CRUDN Request Handler 8 15 • 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 GET Observe
Put
Delete
Embedded Software Lab. @ SKKU Server (Thing Device) Interface 9 15 • E.g., Light, Humidity, Temp
URI, Resource Type
< Get Logic >
Things Meta-Data
IoTivity/resource/examples/IoTivity_Sample_Server/simple_server_temp.h / .cpp File Embedded Software Lab. @ SKKU Server (Thing Device) Interface (2/2) 10 15
Get the data from the Representation
Notify the current message to observers
Sensor Thread Creation
Embedded Software Lab. @ SKKU Simple Client (Android) 11 15 • IoTivityWrapper.java
Listener Callback
Operation
Embedded Software Lab. @ SKKU findResource() - Resource Find Logic 12 15
Found resource info Platform Configuration
Find Resource API
Embedded Software Lab. @ SKKU GET & PUT Function 13 15
To get the value from Representation for GET, OBSERVE
To set the value to Representation for PUT
Embedded Software Lab. @ SKKU IoTivity Communication Demo 15 15 1 /a/temp - PUT Status ON
2 /a/humidity - PUT Status ON 3 4 1 2 /a/temp - Get /a/humidity - Get 3 4
Temperature Humidity
Embedded Software Lab. @ SKKU