Tizen/Artik Iot Practice Part 5 Iotivity Simple Server and Simple Client
Total Page:16
File Type:pdf, Size:1020Kb
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 Function> IoTivity/resource/examples/IoTivity_Sample_Server/resource.h File Resource Creation Logic : Resource Creation and <User Define Virtual Function> ReGisterinG the URI resource put : Set the data sent from the EntityHandler Logic : cline Request HandlinG ParsinG LoGic get : Get the data requested from the Client User-defined Virtual SensorValueRead : Sensor Interface Acquisition Read Thread ChangeResourceRepresentation : Observe Thread LoGic 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 <Temperature Things> 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 <Sensor Logic> <Put Logic> <Observation Logic> 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 Listener Callback> Find Resource API Embedded Software Lab. @ SKKU GET & PUT Function 13 15 <PUT Function> <GET Function> <GET Listener Callback> <Observe Function> Embedded Software Lab. @ SKKU Client Resource Description 14 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.