1 22

Tizen/Artik IoT Lecture Chapter 8. IoTivity P2P Connection

Sungkyunkwan University

Embedded Software Lab. @ SKKU Contents 2 22 • IoTivity API Set • Discovery Subsystem – Registering & Discovering a Resource • Querying Resource State – GET – PUT – POST • Resource Observe • SimpleClient & SimpleServer

Embedded Software Lab. @ SKKU IoTivity API Set 3 22 • IoTivity supports various API set for platforms and languages – , iOS, Android, Ubuntu, OS X, Windows (C/C++, Java, JS etc..) – There are two kinds of API stack : Rich-device and Constrained Devices

Embedded Software Lab. @ SKKU Discovery Subsystem 4 22

Embedded Software Lab. @ SKKU Registering and Discovering a Resource (1/3) 5 22 • Resource Registration and Resource Finding are main functionalities in IoTivity Base Layer

1 2 registerResource(…); 3

RPC Call OCCreateResource(); (1). Server: Registering Resource (2). Client : Find Resource in IP Network (multicast) (3). Client : When the client find resource, the callback function is invoked

1 2

3 Embedded Software Lab. @ SKKU Registering and Discovering a Resource (2/3) 6 22

• Registering a resource API

Embedded Software Lab. @ SKKU Registering and Discovering a Resource (3/3) 7 22

• OCPlatform::findResource (const std::string& host const std::string& resourceName OCConnectivityType connectivityType FindCallback resourceHandler)

Example: simpleClient.cpp ... “/oic/res” = all OIC devices that are discoverable requestURI << OC_RSRVD_WELL_KNOWN_URI;

OCPlatform::findResource(“”, requestURI.str(), CT_DEFAULT, &foundResource);

... à API for Service and Resource discovery (client side only) host == null: multicast resource discovery query Embedded Software Lab. @ SKKU Querying Resource State 8 22 • After registering and discovering states, the clients can invoke GET, PUT query

Embedded Software Lab. @ SKKU Querying Resource State: GET (1/2) 9 22

Embedded Software Lab. @ SKKU Querying Resource State: GET (2/2) 10 22

1 Query

Response Unmarshaling 2

Unmarshaling

Embedded Software Lab. @ SKKU Querying Resource State: PUT (1/2) 11 22

Embedded Software Lab. @ SKKU Querying Resource State: PUT (2/2) 12 22

Query unpacking

Key:Value Packing

Put

Resource Set

Embedded Software Lab. @ SKKU Querying Resource State: POST (1/2) 13 22

• POST can create new resource like PUT

Attribute setting

2

7 Create New Resource 1 Post Invocation 3

Send Response

Embedded Software Lab. @ SKKU Querying Resource State: POST (2/2) 14 22

Check Resource Created 4 8

5 Attribute Check

9

6

New Attribute Setting Embedded Software Lab. @ SKKU Resource Observe (1/5) 15 22 • Observe happens at resource level and operates in server/client model

Embedded Software Lab. @ SKKU Resource Observe (2/5): Sequence Flow 16 22

Embedded Software Lab. @ SKKU Resource Observe (3/5): Sequence Flow 17 22

Embedded Software Lab. @ SKKU Resource Observe (4/5): SimpleClient 18 22 • Observe API

2

1

Embedded Software Lab. @ SKKU Resource Observe (5/5): SimpleServer 19 22 • Observe Registration and notify 1

2

Entity Handler check observe message & push observer into observer list CheckObserverList 3 4 Create Light Value changed Watcher Thread Send Notify

Embedded Software Lab. @ SKKU SimpleClient (Android) 20 22 • IoTivity provides SimpleServer and SimpleClient examples for C/C++ and Andorid – SimpleClient and SimpleServer includes restful APIs such as get, put, post and observe Platfrom Config

Register Resource Platfrom Config

2

1 Find Resource

Embedded Software Lab. @ SKKU SimpleServer - Android 21 22

Observer List Addition

Observing Thread Creation Request Handler

HandleEntity Implementation

Get Resoponse

Embedded Software Lab. @ SKKU Android Simple Client & Server Test 22 22

• Using Bluetooth (RFCOMM over Bluetooth)

Embedded Software Lab. @ SKKU