SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
Build
Resource Server & Client
for OCF Cloud
ryan.kim@data-alliance.com
2018. 8. 30
Cloud Architecture
OCF Cloud :
Resource Directory is used for storing and finding
resources.
Account is used for storing User & Device info.
Message Queue is based on Kafka and used for
message queue.
Cloud Interface process uses Device Server
System module to handle devices.
(*You should put Interface server address, credential
to run sample.)
Resource Server (Controlee) : Things Device
eg> TV, Refrigerator, Air Conditioner, Air Purifier,
Dishwasher...
Resource Client (Controller) : Remote Control App
Build and run IoTivity projects
Install build env
$ sudo apt-get install build-essential git scons libtool autoconf valgrind doxygen wget unzip chrpath
Install development support for external libraries:
$ sudo apt-get install libboost-dev libboost-program-options-dev libboost-thread-dev uuid-dev
libexpat1-dev libglib2.0-dev libsqlite3-dev libcurl4-gnutls-dev
How to build IoTivity projects
$ git clone https://gerrit.iotivity.org/gerrit/p/iotivity.git -b 1.3.1 iotivity-v1.3.1
$ cd iotivity-v1.3.1
$ git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/tinycbor -b v0.4.1
$ git clone https://github.com/ARMmbed/mbedtls.git extlibs/mbedtls/mbedtls -b mbedtls-2.4.2
$ scons cloud/ WITH_TCP=yes RELEASE=yes TARGET_TRANSPORT=IP WITH_CLOUD=yes
WITH_MQ=PUB,SUB SECURED=0 -j 2
Two more Extlib needed.
-j N, --jobs=N Allow N jobs at once.
Sample source code folder and Build output folder
Sample source code folder
iotivity-v1.3.1/cloud/samples/client/airconditioner/
Build output folder
iotivity-v1.3.1/out/linux/x86_64/release/cloud/samples/client/
Run Resource Server ( Controlee Device : TV, Aircon, Dishwasher . . . )
Run Resource Server
$ cd /out/linux/x86_64/release/cloud/samples/client/
$ ./aircon_controlee
Put "[host-ipaddress:port] [authprovider] [authcode]" for sign-up and sign-in and publish resources
Put "[host-ipaddress:port] [uid] [accessToken] 1" for sign-in and publish resources
Interface server address (host-ipaddress)
You should put Interface server address, credential to run sample.
Refer the Interface server address and port number below.
35.227.183.218:5683 ⇐ For OCF Korea Hackathon( ~ 2018. 9. 31), Non secured, Based on v1.3.1
35.221.81.241:5683 ⇐ For Public Test Purpose( ~ 2019. 08. 27), Secured, Based on v1.3.1
Device Sign-up using OAuth 2 Auth Code
Device Sign-up using OAuth 2 Auth Code
To register device, you need 'Auth Code' provided by OAuth 2 provider like Facebook, Google or Github.
IoTivity Cloud project includes 'GitHub' account plugin. To get a 'Auth Code' from 'GitHub' you can make
request to below URL.
https://github.com/login?return_to=/login/oauth/authorize?client_id=378c7c6a465fa4d37816&redirect_uri=htt
p://35.227.183.170:8081/oauth_callback
Once you signed-in, you'll be redirected to other web page include 'Auth Code' in the redirected URL.
http://www.example.com/oauth_callback/?code=3a03a37366c3678aa634
The 'code' part in the URI is the 'Auth Code' from 'GitHub'.
We'll use this code to register and sign-in device.
Device Sign-up using OAuth 2 Auth Code
Run Resource Server ( Controlee Device : TV, Aircon, Dishwasher . . . )
Run Resource Server - Sign Up (To get the UID & AccessToken for the first time.)
$ ./aircon_controlee 35.227.183.218:5683 github 3a03a37366c3678aa634
Auth response received code: 4
accesstoken: de42093f01fd35645bd6038139213c56a6fca3e6
certificate: [..CertInfo..]
expiresin: -1
redirecturi: coap+tcp://127.0.0.1:5683
refreshtoken: (null)
sid: 2a6085d1-815d-4277-baba-4e4e4df91308
tokentype: bearer
uid: 0cf89f61-d999-48cf-857f-73918a37531c
PUT 1/0 to turn on/off air conditioner for observe testing, q to terminate
Publish resource response received, code: 4
Run Resource Server ( Controlee Device : TV, Aircon, Dishwasher . . . )
Run Resource Server - Sign In (After obtaining the UID & AccessToken)
$ ./aircon_controlee 35.227.183.218:5683 0cf89f61-d999-48cf-857f-73918a37531c
de42093f01fd35645bd6038139213c56a6fca3e6
Auth response received code: 4
expiresin: -1
Registering resources to platform...
Publishing resources to cloud result: 0 Waiting Publish default resource response from cloud
result: 0 Waiting Publish user resource response from cloud
Publish resource response received, code: 4
PUT 1/0 to turn on/off air conditioner for observe testing, q to terminate
Publish resource response received, code: 4
Run as a Service (optional)
example service file below
$ vi aircon.service
[Unit]
Description=OCF Airconditioner
Requires=network-online.target
[Service]
Type=simple
RestartSec=3s
User=pi
Group=pi
ExecStart=/home/pi/aircon/airconditioner_controlee 35.227.183.218:5683 0cf89f61-d999-48cf-857f-73918a37531c
de42093f01fd35645bd6038139213c56a6fca3e6
WorkingDirectory=/home/pi/aircon
Restart=always
[Install]
WantedBy=multi-user.target
Run as a Service (optional)
Start service
$ systemctl enable aircon.service && systemctl start aircon.service
Restart service
$ systemctl restart aircon.service
Stop service
$ systemctl stop aircon.service && systemctl disable aircon.service
Service log
$ journalctl -u aircon.service -f
Run Resource Client ( Controller Device : Remote Controller App )
Run Resource Client - Sign Up (To get the UID & AccessToken for the first time.)
$ ./aircon_controller 35.227.183.218:5683 github 9d31d32e18c3e38bd559
Login/out response received code: 4
accesstoken: a0572063607baae269e5fdc336367d295f1efbdc
certificate: [..CertInfo..]
redirecturi: coap+tcp://127.0.0.1:5683
refreshtoken: (null)
sid: 2a6085d1-815d-4277-baba-4e4e4df91308
tokentype: bearer
uid: 0cf89f61-d999-48cf-857f-73918a37531c
Login/out response received code: 4
expiresin: -1
Finding airconditioner result: 0
Device found: /di/1a78ae17-3dc0-48f8-a51e-b19574de198b/oic/d
DI: 1a78ae17-3dc0-48f8-a51e-b19574de198b
PUT 1/0 to turn on/off air conditioner, q to terminate
Run Resource Client ( Controller Device : Remote Controller App )
Run Resource Client - Sign In (After obtaining the UID & AccessToken)
$ ./aircon_controller 35.227.183.218:5683 0cf89f61-d999-48cf-857f-73918a37531c
a0572063607baae269e5fdc336367d295f1efbdc
aircon_controlee.cpp (1)
int main(int argc, char *argv[])
{
if (argc != 4)
{
cout << "Put "[host-ipaddress:port] [authprovider] [authcode]" for sign-up and sign-in and publish resources"
<< endl;
cout << "Put "[host-ipaddress:port] [uid] [accessToken]" for sign-in and publish resources" <<
endl;
return 0;
}
. . .
aircon_controlee.cpp (2)
int main(int argc, char *argv[])
{
. . .
if (strlen(argv[2]) > 35)
{
accountMgr->signIn(argv[2], argv[3], &handleLoginoutCB);
g_callbackLock.wait(lock);
}
else
{
accountMgr->signUp(argv[2], argv[3], &handleLoginoutCB);
g_callbackLock.wait(lock);
accountMgr->signIn(g_uid, g_accesstoken, &handleLoginoutCB);
g_callbackLock.wait(lock);
}
. . .
aircon_controlee.cpp (3)
int main(int argc, char *argv[])
{
. . .
cout << "Registering resources to platform..." << endl;
AirConditionerResource airConditioner("/aircon/0", { "x.org.iotivity.ac" }, { DEFAULT_INTERFACE,
BATCH_INTERFACE, LINK_INTERFACE });
BinarySwitchResource binarySwitch("/power/0", { "oic.r.switch.binary" }, { DEFAULT_INTERFACE });
TemperatureResource temperature("/temperature/0", { "oic.r.temperature" }, { DEFAULT_INTERFACE });
FirmwareResource firmware("/firmware", { "x.org.iotivity.firmware" }, { DEFAULT_INTERFACE });
. . .
aircon_controlee.cpp (4)
int main(int argc, char *argv[])
{
. . .
result = OCPlatform::registerResource(airConditioner.m_handle,
uri, rt, itf,
bind(&AirConditionerResource::entityHandler
, &airConditioner, placeholders::_1),
OC_DISCOVERABLE);
. . .
result = OCPlatform::registerResource(binarySwitch.m_handle,
uri, rt, itf,
bind(&BinarySwitchResource::entityHandler
, &binarySwitch, placeholders::_1),
OC_OBSERVABLE);
aircon_controlee.cpp (5)
int main(int argc, char *argv[])
{
. . .
while (true)
{
switch (cmd[0])
{
case '1':
rep.setValue(string("value"), true);
binarySwitch.setBinarySwitchRepresentation(rep);
break;
case '0':
rep.setValue(string("value"), false);
binarySwitch.setBinarySwitchRepresentation(rep);
break;
}
}
aircon_controlee.cpp (6)
class BinarySwitchResource : public Resource //oic.r.switch.binary
{
private:
bool m_value;
void setBinarySwitchRepresentation(OCRepresentation &rep)
{
bool value;
if (rep.getValue("value", value))
{
m_value = value;
m_representation.setValue("value", m_value);
cout << "tttt" << "value: " << m_value << endl;
propagate();
}
}
#if defined(WIRINGPI)
if (m_value)
{
digitalWrite (DEVICE_PIN, HIGH);
}
else
{
digitalWrite (DEVICE_PIN, LOW);
}
#endif
aircon_controller.cpp (1)
int main(int argc, char *argv[])
{
if (argc != 4)
{
cout << "Put "[host-ipaddress:port] [authprovider] [authcode]" for sign-up and sign-in and publish resources"
<< endl;
cout << "Put "[host-ipaddress:port] [uid] [accessToken]" for sign-in and publish resources" <<
endl;
return 0;
}
. . .
aircon_controller.cpp (2)
int main(int argc, char *argv[])
{
. . .
if (strlen(argv[2]) > 35)
{
accountMgr->signIn(argv[2], argv[3], &handleLoginoutCB);
g_callbackLock.wait(lock);
}
else
{
accountMgr->signUp(argv[2], argv[3], &handleLoginoutCB);
g_callbackLock.wait(lock);
accountMgr->signIn(g_uid, g_accesstoken, &handleLoginoutCB);
g_callbackLock.wait(lock);
}
. . .
aircon_controller.cpp (3)
int main(int argc, char *argv[])
{
. . .
cout << "Finding airconditioner ";
result = OCPlatform::findResource(g_host, "/oic/res?rt=oic.wk.d",
static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4),
&foundDevice, &errorFoundDevice);
cout << " result: " << result << endl;
. . . void foundDevice(shared_ptr<OC::OCResource> resource)
{
OCPlatform::findResource(g_host, searchQuery,
static_cast<OCConnectivityType>(CT_ADAPTER_TCP |
CT_IP_USE_V4),
&foundAirconditionerResource);
aircon_controller.cpp (4)
void foundAirconditionerResource(shared_ptr<OC::OCResource> resource)
{
. . .
resource->get(query, &getCollectionResource);
void getCollectionResource(const HeaderOptions &,
const OCRepresentation &rep, const int ecode)
{
g_binaryswitchResource = OCPlatform::constructResourceObject(g_host,
it->getUri(),
static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4), true,
aircon_controller.cpp (5)
void turnOnOffSwitch(bool toTurn)
{
if (g_binaryswitchResource == nullptr)
{
cout << "Binary switch not found" << endl;
return;
}
OCRepresentation binarySwitch;
binarySwitch.setValue("value", toTurn);
QueryParamsMap query;
g_binaryswitchResource->post("oic.r.switch.binary", DEFAULT_INTERFACE, binarySwitch, query,
&onPost);
}
https://wiki.iotivity.org/build_for_your_system
Build IoTivity project for
Product Perspective
Artik053s ATSAM4S-XPRO + WINC1500 + Crypto
Thank you...

Weitere ähnliche Inhalte

Was ist angesagt?

Program for hamming code using c
Program for hamming code using cProgram for hamming code using c
Program for hamming code using csnsanth
 
Cosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationCosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationFIWARE
 
Building Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisBuilding Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisFIWARE
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixManish Pandit
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQAFest
 
Durable functions
Durable functionsDurable functions
Durable functions명신 김
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploySimon Su
 
Java client socket-20070327
Java client socket-20070327Java client socket-20070327
Java client socket-20070327Tsu-Fen Han
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot Nidhi Chauhan
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots DeepAnshu Sharma
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialJeff Smith
 
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo Omura
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo OmuraSPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo Omura
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo OmuraPreferred Networks
 
Browser-based Secure Remote Access for the Internet of Things
Browser-based Secure Remote Access for the Internet of ThingsBrowser-based Secure Remote Access for the Internet of Things
Browser-based Secure Remote Access for the Internet of ThingsGünter Obiltschnig
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of ControlChad Hietala
 
Score (smart contract for icon)
Score (smart contract for icon) Score (smart contract for icon)
Score (smart contract for icon) Doyun Hwang
 
Automated reduction of attack surface using call graph enumeration
Automated reduction of attack surface using call graph enumerationAutomated reduction of attack surface using call graph enumeration
Automated reduction of attack surface using call graph enumerationRuo Ando
 

Was ist angesagt? (18)

Program for hamming code using c
Program for hamming code using cProgram for hamming code using c
Program for hamming code using c
 
Cosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationCosmos, Big Data GE Implementation
Cosmos, Big Data GE Implementation
 
Building Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisBuilding Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEis
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
 
Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
Java client socket-20070327
Java client socket-20070327Java client socket-20070327
Java client socket-20070327
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
 
Programming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorial
 
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo Omura
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo OmuraSPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo Omura
SPIFFE Meetup Tokyo #2 - Attestation Internals in SPIRE - Shingo Omura
 
Browser-based Secure Remote Access for the Internet of Things
Browser-based Secure Remote Access for the Internet of ThingsBrowser-based Secure Remote Access for the Internet of Things
Browser-based Secure Remote Access for the Internet of Things
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
Hack ASP.NET website
Hack ASP.NET websiteHack ASP.NET website
Hack ASP.NET website
 
Score (smart contract for icon)
Score (smart contract for icon) Score (smart contract for icon)
Score (smart contract for icon)
 
Automated reduction of attack surface using call graph enumeration
Automated reduction of attack surface using call graph enumerationAutomated reduction of attack surface using call graph enumeration
Automated reduction of attack surface using call graph enumeration
 

Ähnlich wie Build Resource Server & Client for OCF Cloud

Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8FIWARE
 
IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2John Staveley
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptxssuserb4d806
 
Sigfox World Expo - Advanced Workshop
Sigfox World Expo - Advanced WorkshopSigfox World Expo - Advanced Workshop
Sigfox World Expo - Advanced WorkshopNicolas Lesconnec
 
Tick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleepTick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleepGianluca Arbezzano
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
Time Series Database and Tick Stack
Time Series Database and Tick StackTime Series Database and Tick Stack
Time Series Database and Tick StackGianluca Arbezzano
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Yuriy Senko
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020Matt Raible
 
Swift hardware hacking @ try! Swift
Swift hardware hacking @ try! SwiftSwift hardware hacking @ try! Swift
Swift hardware hacking @ try! SwiftSally Shepard
 
SE2016 Android Denis Zhuchinski "Ways of enhancing application security"
SE2016 Android Denis Zhuchinski "Ways of enhancing application security"SE2016 Android Denis Zhuchinski "Ways of enhancing application security"
SE2016 Android Denis Zhuchinski "Ways of enhancing application security"Inhacking
 
FIWARE Primer - Learn FIWARE in 60 Minutes
FIWARE Primer - Learn FIWARE in 60 MinutesFIWARE Primer - Learn FIWARE in 60 Minutes
FIWARE Primer - Learn FIWARE in 60 MinutesFederico Michele Facca
 
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 Minutes
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 MinutesFederico Michele Facca - FIWARE Primer - Learn FIWARE in 60 Minutes
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 MinutesCodemotion
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & morePower your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & morewesley chun
 
以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界Amazon Web Services
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScriptQiangning Hong
 
Build Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionBuild Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionHiveMQ
 
Fiware IoT Proposal & Community
Fiware IoT Proposal & Community Fiware IoT Proposal & Community
Fiware IoT Proposal & Community TIDChile
 

Ähnlich wie Build Resource Server & Client for OCF Cloud (20)

Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8Fiware io t_ul20_cpbr8
Fiware io t_ul20_cpbr8
 
IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2IoT on Raspberry PI v1.2
IoT on Raspberry PI v1.2
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
 
Sigfox World Expo - Advanced Workshop
Sigfox World Expo - Advanced WorkshopSigfox World Expo - Advanced Workshop
Sigfox World Expo - Advanced Workshop
 
Tick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleepTick Stack - Listen your infrastructure and please sleep
Tick Stack - Listen your infrastructure and please sleep
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Time Series Database and Tick Stack
Time Series Database and Tick StackTime Series Database and Tick Stack
Time Series Database and Tick Stack
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Swift hardware hacking @ try! Swift
Swift hardware hacking @ try! SwiftSwift hardware hacking @ try! Swift
Swift hardware hacking @ try! Swift
 
SE2016 Android Denis Zhuchinski "Ways of enhancing application security"
SE2016 Android Denis Zhuchinski "Ways of enhancing application security"SE2016 Android Denis Zhuchinski "Ways of enhancing application security"
SE2016 Android Denis Zhuchinski "Ways of enhancing application security"
 
FIWARE Primer - Learn FIWARE in 60 Minutes
FIWARE Primer - Learn FIWARE in 60 MinutesFIWARE Primer - Learn FIWARE in 60 Minutes
FIWARE Primer - Learn FIWARE in 60 Minutes
 
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 Minutes
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 MinutesFederico Michele Facca - FIWARE Primer - Learn FIWARE in 60 Minutes
Federico Michele Facca - FIWARE Primer - Learn FIWARE in 60 Minutes
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & morePower your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides & more
 
以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界以Device Shadows與Rules Engine串聯實體世界
以Device Shadows與Rules Engine串聯實體世界
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
 
Build Your Own HiveMQ Extension
Build Your Own HiveMQ ExtensionBuild Your Own HiveMQ Extension
Build Your Own HiveMQ Extension
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
Fiware IoT Proposal & Community
Fiware IoT Proposal & Community Fiware IoT Proposal & Community
Fiware IoT Proposal & Community
 
IoT on Raspberry Pi
IoT on Raspberry PiIoT on Raspberry Pi
IoT on Raspberry Pi
 

Kürzlich hochgeladen

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Kürzlich hochgeladen (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

Build Resource Server & Client for OCF Cloud

  • 1. Build Resource Server & Client for OCF Cloud ryan.kim@data-alliance.com 2018. 8. 30
  • 2. Cloud Architecture OCF Cloud : Resource Directory is used for storing and finding resources. Account is used for storing User & Device info. Message Queue is based on Kafka and used for message queue. Cloud Interface process uses Device Server System module to handle devices. (*You should put Interface server address, credential to run sample.) Resource Server (Controlee) : Things Device eg> TV, Refrigerator, Air Conditioner, Air Purifier, Dishwasher... Resource Client (Controller) : Remote Control App
  • 3. Build and run IoTivity projects Install build env $ sudo apt-get install build-essential git scons libtool autoconf valgrind doxygen wget unzip chrpath Install development support for external libraries: $ sudo apt-get install libboost-dev libboost-program-options-dev libboost-thread-dev uuid-dev libexpat1-dev libglib2.0-dev libsqlite3-dev libcurl4-gnutls-dev How to build IoTivity projects $ git clone https://gerrit.iotivity.org/gerrit/p/iotivity.git -b 1.3.1 iotivity-v1.3.1 $ cd iotivity-v1.3.1 $ git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/tinycbor -b v0.4.1 $ git clone https://github.com/ARMmbed/mbedtls.git extlibs/mbedtls/mbedtls -b mbedtls-2.4.2 $ scons cloud/ WITH_TCP=yes RELEASE=yes TARGET_TRANSPORT=IP WITH_CLOUD=yes WITH_MQ=PUB,SUB SECURED=0 -j 2 Two more Extlib needed. -j N, --jobs=N Allow N jobs at once.
  • 4. Sample source code folder and Build output folder Sample source code folder iotivity-v1.3.1/cloud/samples/client/airconditioner/ Build output folder iotivity-v1.3.1/out/linux/x86_64/release/cloud/samples/client/
  • 5. Run Resource Server ( Controlee Device : TV, Aircon, Dishwasher . . . ) Run Resource Server $ cd /out/linux/x86_64/release/cloud/samples/client/ $ ./aircon_controlee Put "[host-ipaddress:port] [authprovider] [authcode]" for sign-up and sign-in and publish resources Put "[host-ipaddress:port] [uid] [accessToken] 1" for sign-in and publish resources
  • 6. Interface server address (host-ipaddress) You should put Interface server address, credential to run sample. Refer the Interface server address and port number below. 35.227.183.218:5683 ⇐ For OCF Korea Hackathon( ~ 2018. 9. 31), Non secured, Based on v1.3.1 35.221.81.241:5683 ⇐ For Public Test Purpose( ~ 2019. 08. 27), Secured, Based on v1.3.1
  • 7. Device Sign-up using OAuth 2 Auth Code Device Sign-up using OAuth 2 Auth Code To register device, you need 'Auth Code' provided by OAuth 2 provider like Facebook, Google or Github. IoTivity Cloud project includes 'GitHub' account plugin. To get a 'Auth Code' from 'GitHub' you can make request to below URL. https://github.com/login?return_to=/login/oauth/authorize?client_id=378c7c6a465fa4d37816&redirect_uri=htt p://35.227.183.170:8081/oauth_callback Once you signed-in, you'll be redirected to other web page include 'Auth Code' in the redirected URL. http://www.example.com/oauth_callback/?code=3a03a37366c3678aa634 The 'code' part in the URI is the 'Auth Code' from 'GitHub'. We'll use this code to register and sign-in device.
  • 8. Device Sign-up using OAuth 2 Auth Code
  • 9. Run Resource Server ( Controlee Device : TV, Aircon, Dishwasher . . . ) Run Resource Server - Sign Up (To get the UID & AccessToken for the first time.) $ ./aircon_controlee 35.227.183.218:5683 github 3a03a37366c3678aa634 Auth response received code: 4 accesstoken: de42093f01fd35645bd6038139213c56a6fca3e6 certificate: [..CertInfo..] expiresin: -1 redirecturi: coap+tcp://127.0.0.1:5683 refreshtoken: (null) sid: 2a6085d1-815d-4277-baba-4e4e4df91308 tokentype: bearer uid: 0cf89f61-d999-48cf-857f-73918a37531c PUT 1/0 to turn on/off air conditioner for observe testing, q to terminate Publish resource response received, code: 4
  • 10. Run Resource Server ( Controlee Device : TV, Aircon, Dishwasher . . . ) Run Resource Server - Sign In (After obtaining the UID & AccessToken) $ ./aircon_controlee 35.227.183.218:5683 0cf89f61-d999-48cf-857f-73918a37531c de42093f01fd35645bd6038139213c56a6fca3e6 Auth response received code: 4 expiresin: -1 Registering resources to platform... Publishing resources to cloud result: 0 Waiting Publish default resource response from cloud result: 0 Waiting Publish user resource response from cloud Publish resource response received, code: 4 PUT 1/0 to turn on/off air conditioner for observe testing, q to terminate Publish resource response received, code: 4
  • 11. Run as a Service (optional) example service file below $ vi aircon.service [Unit] Description=OCF Airconditioner Requires=network-online.target [Service] Type=simple RestartSec=3s User=pi Group=pi ExecStart=/home/pi/aircon/airconditioner_controlee 35.227.183.218:5683 0cf89f61-d999-48cf-857f-73918a37531c de42093f01fd35645bd6038139213c56a6fca3e6 WorkingDirectory=/home/pi/aircon Restart=always [Install] WantedBy=multi-user.target
  • 12. Run as a Service (optional) Start service $ systemctl enable aircon.service && systemctl start aircon.service Restart service $ systemctl restart aircon.service Stop service $ systemctl stop aircon.service && systemctl disable aircon.service Service log $ journalctl -u aircon.service -f
  • 13. Run Resource Client ( Controller Device : Remote Controller App ) Run Resource Client - Sign Up (To get the UID & AccessToken for the first time.) $ ./aircon_controller 35.227.183.218:5683 github 9d31d32e18c3e38bd559 Login/out response received code: 4 accesstoken: a0572063607baae269e5fdc336367d295f1efbdc certificate: [..CertInfo..] redirecturi: coap+tcp://127.0.0.1:5683 refreshtoken: (null) sid: 2a6085d1-815d-4277-baba-4e4e4df91308 tokentype: bearer uid: 0cf89f61-d999-48cf-857f-73918a37531c Login/out response received code: 4 expiresin: -1 Finding airconditioner result: 0 Device found: /di/1a78ae17-3dc0-48f8-a51e-b19574de198b/oic/d DI: 1a78ae17-3dc0-48f8-a51e-b19574de198b PUT 1/0 to turn on/off air conditioner, q to terminate
  • 14. Run Resource Client ( Controller Device : Remote Controller App ) Run Resource Client - Sign In (After obtaining the UID & AccessToken) $ ./aircon_controller 35.227.183.218:5683 0cf89f61-d999-48cf-857f-73918a37531c a0572063607baae269e5fdc336367d295f1efbdc
  • 15. aircon_controlee.cpp (1) int main(int argc, char *argv[]) { if (argc != 4) { cout << "Put "[host-ipaddress:port] [authprovider] [authcode]" for sign-up and sign-in and publish resources" << endl; cout << "Put "[host-ipaddress:port] [uid] [accessToken]" for sign-in and publish resources" << endl; return 0; } . . .
  • 16. aircon_controlee.cpp (2) int main(int argc, char *argv[]) { . . . if (strlen(argv[2]) > 35) { accountMgr->signIn(argv[2], argv[3], &handleLoginoutCB); g_callbackLock.wait(lock); } else { accountMgr->signUp(argv[2], argv[3], &handleLoginoutCB); g_callbackLock.wait(lock); accountMgr->signIn(g_uid, g_accesstoken, &handleLoginoutCB); g_callbackLock.wait(lock); } . . .
  • 17. aircon_controlee.cpp (3) int main(int argc, char *argv[]) { . . . cout << "Registering resources to platform..." << endl; AirConditionerResource airConditioner("/aircon/0", { "x.org.iotivity.ac" }, { DEFAULT_INTERFACE, BATCH_INTERFACE, LINK_INTERFACE }); BinarySwitchResource binarySwitch("/power/0", { "oic.r.switch.binary" }, { DEFAULT_INTERFACE }); TemperatureResource temperature("/temperature/0", { "oic.r.temperature" }, { DEFAULT_INTERFACE }); FirmwareResource firmware("/firmware", { "x.org.iotivity.firmware" }, { DEFAULT_INTERFACE }); . . .
  • 18. aircon_controlee.cpp (4) int main(int argc, char *argv[]) { . . . result = OCPlatform::registerResource(airConditioner.m_handle, uri, rt, itf, bind(&AirConditionerResource::entityHandler , &airConditioner, placeholders::_1), OC_DISCOVERABLE); . . . result = OCPlatform::registerResource(binarySwitch.m_handle, uri, rt, itf, bind(&BinarySwitchResource::entityHandler , &binarySwitch, placeholders::_1), OC_OBSERVABLE);
  • 19. aircon_controlee.cpp (5) int main(int argc, char *argv[]) { . . . while (true) { switch (cmd[0]) { case '1': rep.setValue(string("value"), true); binarySwitch.setBinarySwitchRepresentation(rep); break; case '0': rep.setValue(string("value"), false); binarySwitch.setBinarySwitchRepresentation(rep); break; } }
  • 20. aircon_controlee.cpp (6) class BinarySwitchResource : public Resource //oic.r.switch.binary { private: bool m_value; void setBinarySwitchRepresentation(OCRepresentation &rep) { bool value; if (rep.getValue("value", value)) { m_value = value; m_representation.setValue("value", m_value); cout << "tttt" << "value: " << m_value << endl; propagate(); } } #if defined(WIRINGPI) if (m_value) { digitalWrite (DEVICE_PIN, HIGH); } else { digitalWrite (DEVICE_PIN, LOW); } #endif
  • 21. aircon_controller.cpp (1) int main(int argc, char *argv[]) { if (argc != 4) { cout << "Put "[host-ipaddress:port] [authprovider] [authcode]" for sign-up and sign-in and publish resources" << endl; cout << "Put "[host-ipaddress:port] [uid] [accessToken]" for sign-in and publish resources" << endl; return 0; } . . .
  • 22. aircon_controller.cpp (2) int main(int argc, char *argv[]) { . . . if (strlen(argv[2]) > 35) { accountMgr->signIn(argv[2], argv[3], &handleLoginoutCB); g_callbackLock.wait(lock); } else { accountMgr->signUp(argv[2], argv[3], &handleLoginoutCB); g_callbackLock.wait(lock); accountMgr->signIn(g_uid, g_accesstoken, &handleLoginoutCB); g_callbackLock.wait(lock); } . . .
  • 23. aircon_controller.cpp (3) int main(int argc, char *argv[]) { . . . cout << "Finding airconditioner "; result = OCPlatform::findResource(g_host, "/oic/res?rt=oic.wk.d", static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4), &foundDevice, &errorFoundDevice); cout << " result: " << result << endl; . . . void foundDevice(shared_ptr<OC::OCResource> resource) { OCPlatform::findResource(g_host, searchQuery, static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4), &foundAirconditionerResource);
  • 24. aircon_controller.cpp (4) void foundAirconditionerResource(shared_ptr<OC::OCResource> resource) { . . . resource->get(query, &getCollectionResource); void getCollectionResource(const HeaderOptions &, const OCRepresentation &rep, const int ecode) { g_binaryswitchResource = OCPlatform::constructResourceObject(g_host, it->getUri(), static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4), true,
  • 25. aircon_controller.cpp (5) void turnOnOffSwitch(bool toTurn) { if (g_binaryswitchResource == nullptr) { cout << "Binary switch not found" << endl; return; } OCRepresentation binarySwitch; binarySwitch.setValue("value", toTurn); QueryParamsMap query; g_binaryswitchResource->post("oic.r.switch.binary", DEFAULT_INTERFACE, binarySwitch, query, &onPost); }