This document provides instructions for building an IoT cloud platform and sample IoT devices using IoTivity. It describes:
- The cloud architecture including a resource directory, account service, and message queue.
- How to build and run IoTivity projects including installing dependencies and building sample device and controller projects.
- How to run the resource server (device) and client (controller) projects, including signing up, signing in, publishing resources, and controlling devices remotely.
- Sample code is provided to show how devices can be registered and resources can be controlled via the cloud platform using IoTivity.
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.
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.
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;
}
. . .