1 27

Tizen/Artik IoT Practice Part 3 Building IoTivity

Sungkyunkwan University

Embedded Software Lab. @ SKKU Contents 2 27 • IoTivity’s Target Platforms • How to Clone IoTivity Source Code • How to Clone IoTivity Source Code for • How to Build IoTivity – for Tizen/Artik – for Ubuntu/x86 – for Raspberry Pi 2 – for Android – for Arduino • How to Contribute to IoTivity Project

Embedded Software Lab. @ SKKU IoTivity’s Target Platforms 3 27

• IoTivity’s Multi-Platform Support – Architectures: x86, x86_64, arm-v7a, arm, arm64 – OS: , android, tizen, arduino • Scons – IoTivity’s default build tool – Support for Multi-platform cross build – ex) $ scons TARGET_ARCH=arm TARGET_OS=android

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code 4 27

1. Sign up and Log in IoTivity Gerrit server – Go to https://gerrit.iotivity.org/gerrit/ 2. Go to “Settings → SSH Public Keys” 3. Make SSH public/private keys – $ ssh-keygen – Press enter for the every questions

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code 5 27

4. Copy the public key to the form – Copy “$ cat ~/.ssh/id_rsa.pub” to the form on the web site

Copy!

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code 6 27

5. Create or Edit SSH Config – $ gedit ~/.ssh/config – Add following text to ~/.ssh/config • Please fill as your own IoTivity Gerrit ID.

Host gerrit.iotivity.org Hostname gerrit.iotivity.org IdentityFile ~/.ssh/id_rsa User Port 29418 6. Clone source code of IoTivity – $ git clone ssh://gerrit.iotivity.org/iotivity 7. Clone dependency library (tinycbor) – $ git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/tinycbor Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code 7 27

8. Trouble-shooting for tinycbor library – Add following code to extlibs/tinycbor/SConscript cbor_src = [ … os.path.join(cborDir,‘src/cborparser_dup_string.c’), ]

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code for Tizen 8 27

• You should have an access right to review server for accessing Tizen source code. 1. Register a Tizen developer ID 1. Go to developer.tizen.org/ko.

2. You can log in Tizen review server (review.tizen.org).

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code for Tizen 9 27

2. Review Server: Configuration 1. $ gedit ~/.ssh/config – Enter your Gerrit ID.

Host tizen ~/.ssh/config Hostname review.tizen.org IdentityFile ~/.ssh/id_rsa User GerritID Port 29418

Host review.tizen.org Hostname review.tizen.org IdentityFile ~/.ssh/id_rsa User GerritID Port 29418

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code for Tizen 10 27

3. Sign up and Log in Tizen Gerrit server – Go to https://review.tizen.org 4. Go to “Settings → SSH Public Keys” 5. Make SSH public/private keys – $ ssh-keygen – Press enter for the every questions

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code for Tizen 11 27

6. Copy the public key to the form – Copy “$ cat ~/.ssh/id_rsa.pub” to the form on the web site

Copy!

Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code for Tizen 12 27

7. Create or Edit SSH Config – $ gedit ~/.ssh/config – Add following text to ~/.ssh/config • Please fill as your own IoTivity Gerrit ID.

Host gerrit.iotivity.org Hostname gerrit.iotivity.org IdentityFile ~/.ssh/id_rsa User 8. Clone source code of IoTivity Port 29418 – $ git clone ssh://gerrit.iotivity.org/iotivity 9. Test ssh server connection – $ ssh tizen – $ ssh review.tizen.org Embedded Software Lab. @ SKKU How to Clone IoTivity Source Code for Tizen 13 27

10.Identify the URL of IoTivity Source Code for Tizen 1. Go to https://review.tizen.org/ 2. Projects  List 3. Search “iotivity” 4. Click “platform/upstream/iotivity” (for Tizen 3.0) 11.CLone the IoTivity Source Code for Tizen 10. $ git clone git://git.tizen.org/platform/upstream/iotivity

Embedded Software Lab. @ SKKU How to Build IoTivity for Tizen/Artik 14 27

• Assume to build it on x86_64 device running Ubuntu 16.04. 1. Add Tizen development tool repository to APT repository list. 1. $ sudo gedit /etc/apt/sources.list 2. Add below code /etc/apt/sources.list deb http://download.tizen.org/tools/pre-release/Ubuntu_16.04 / 3. $ sudo apt-get update 2. Install packages of GBS, MIC. 1. $ sudo apt-get install gbs mic Embedded Software Lab. @ SKKU How to Build IoTivity for Tizen/Artik 15 27

3. Edit .gbs.conf 1. $ vi ~/.gbs.conf [general] ~/.gbs.conf tmpdir=/var/tmp/ profile=profile.tizen3.0_artik [repo.tizen3.0_base] url=http://download.tizen.org/snapshots/tizen/base/latest/repos/arm/packages [repo.tizen3.0_artik] url=http://download.tizen.org/snapshots/tizen/common_artik/latest/repos/arm- wayland/packages [repo.tizen3.0_common_arm_wayland] url=http://download.tizen.org/snapshots/tizen/common/latest/repos/arm- wayland/packages [profile.tizen3.0_artik] repos=repo.tizen3.0_base, repo.tizen3.0_artik, repo.tizen3.0_common_arm_wayland Embedded Software Lab. @ SKKU How to Build IoTivity for Tizen/Artik 16 27 4. Build 1. $ gbs build -A armv7l --include-all – -A : i586, x86_64, armv7l – --include-all: option for building working directory

Embedded Software Lab. @ SKKU How to Build IoTivity for Tizen/Artik 17 27

5. Connect Artik and PC with USB cable 6. Push the RPM package file to Artik 1. $ sdb push ~/GBS- ROOT/local/repos/tizen3.0_artik/armv7l/RPMS/iotivi ty-1.1.1-0.armv7l.rpm /sdcard/ 7. Install on Artik 10 1. $ sdb root on 2. $ sdb shell 3. $ rpm -ivh /sdcard/iotivity- 1.1.1-0.armv7l.rpm Embedded Software Lab. @ SKKU How to Build IoTivity for Tizen/Artik 18 27

• Many IoTivity-related packages are made after build. – iotivity-1.1.1-0.armv7l.rpm – iotivity-devel-1.1.1-0.armv7l.rpm – iotivity-service-1.1.1-0.armv7l.rpm – iotivity-test-1.1.1-0.armv7l.rpm

Embedded Software Lab. @ SKKU How to Build IoTivity for Ubuntu/x86 19 27 • Assume to build it on x86_64 device running Ubuntu 16.04. 1. Install dependency packages – $ sudo apt-get install dos2unix libboost-thread-dev 2. Build – $ scons -j8 • -jX: build with X threads 3. Test – Open two terminal windows: $ cd out/linux/x86_64/release/resource/examples – On your first terminal window, enter: ./simpleserver – On your second terminal window, enter: ./simpleclient

Embedded Software Lab. @ SKKU How to Build IoTivity for Raspberry Pi 2 20 27 • Assume to build it on Raspberry Pi 2 running Raspbian. 1. Install dependency packages – $ sudo apt-get install dos2unix scons build-essential libboost-dev libexpat1-dev libboost-thread-dev 2. Build – $ scons TARGET_ARCH=arm -j4 • -jX: build with X threads 3. Test – Open two terminal windows: $ cd out/linux/arm/release/resource/examples – On your first terminal window, enter: ./simpleserver – On your second terminal window, enter: ./simpleclient

Embedded Software Lab. @ SKKU Expected Test Result 21 27 Terminal 1 Terminal 2 $ ./simpleserver $ ./simpleclient Created resource. <===Setting ObserveType to Observe and ConnectivityType to IP===> Added Interface and Type Waiting Finding Resource... 0: Finding Resource for second time... In entity handler wrapper: In foundResource In Server CPP entity handler: In foundResource requestFlag : Request Found resource 31313131-3131-3131-3131-313131313131/oic/sec/doxm requestType : GET for the first time on server with ID: In foundResource 0: In entity handler wrapper: GET request was successful In Server CPP entity handler: Resource URI: /a/light requestFlag : Request state: false requestType : PUT power: 0 state: 1 name: John's light power: 15 Putting light representation... PUT request was successful state: true power: 15 name: John's light Posting light representation...

Embedded Software Lab. @ SKKU How to Build IoTivity for Android 22 27 • Assume to build it on x86_64 device running Ubuntu 16.04. 1. Install dependency packages – $ sudo apt-get install dos2unix libboost-thread-dev 2. Install Android SDK (API 21) – Option 1. Direct Setting of Android SDK System • Download Android SDK Bundle with Eclipse (32bit용, 64bit용) • $ /tools/android • Choose both “Android SDK Build-tools (Rev. 20)” and “Android 5.0.1 (API 21) > SDK Platform”  ”Install 2 packages” – Option 2. Download Preset Android Bundle • http://nyx.skku.ac.kr/iot-lecture/adt-android-21.tar.gz

Embedded Software Lab. @ SKKU How to Build IoTivity for Android 23 27

3. Build – $ scons TARGET_OS=android TARGET_ARCH=armeabi-v7a ANDROID_HOME= -j8 • Output: APK files (Install them with ’adb install’) – android/examples/*/build/outputs/apk/*.apk – $ find . –name “*.apk”:

./android/examples/simplebase/build/outputs/apk/simplebase-debug-unaligned.apk ./android/examples/simplebase/build/outputs/apk/simplebase-release-unsigned.apk ./android/examples/simplebase/build/outputs/apk/simplebase-debug.apk ./android/examples/simpleclient/build/outputs/apk/simpleclient-debug.apk ./android/examples/simpleclient/build/outputs/apk/simpleclient-release-unsigned.apk ./android/examples/simpleclient/build/outputs/apk/simpleclient-debug-unaligned.apk ./android/examples/devicediscoveryclient/build/outputs/apk/devicediscoveryclient-debug.apk ... Embedded Software Lab. @ SKKU How to Test IoTivity for Android 24 27

• A challenge in IoTivity for Android – Since most Android devices and network gateways do not support Wi-fi Multicast, multicast discovery may not work. • Enable Unicast Discovery for SimpleClient App 1. Check the IP address of device running SimpleServer 2. Edit SimpleClient Android App, and enter the server’s IP address (Refer to next page) 3. Rebuild IoTivity for Android

Embedded Software Lab. @ SKKU How to Test IoTivity for Android 25 27

• android/examples/simpleclient/src/main/java/org/iotivity/base/exampl es/SimpleClient.java private void startSimpleClient() { … try { … OcPlatform.findResource(“192.168.0.123”, requestUri, EnumSet.of(OcConnectivityType.CT_DEFAULT), this ); … OcPlatform.findResource(“192.168.0.123”, requestUri, EnumSet.of(OcConnectivityType.CT_DEFAULT), this ); … } Embedded Software Lab. @ SKKU How to Build IoTivity for Arduino 26 27

• Assume that Arduino Due + Wi-fi Shield(32UC3A1512-U) is target, and host machine is Ubuntu PC. 1. Upgrade the firmware of Wi-fi shield to v1.1.0 – Existing IoTivity run on only Wi-fi Shield Firmware v1.1.0. 1. Set the DFU Jumper of Wi-fi Shield 2. Connect the Wi-fi Shield’s DFU Programming Port to Mini-USB cable 3. Download Arduino Sketch for Ubuntu 4. Go to Wi-fi shield firmware’s script directory 1. $ cd 2. $ cd ./hardware/arduino/avr/firmware/wifishield/script 5. Run Firmware Upgrade Script 1. $ ./ArduinoWifiShield_upgrade.sh

Embedded Software Lab. @ SKKU How to Build IoTivity for Arduino 27 27

2. Connect Arduino-Due’s Programming Port to USB 3. Build – Dependent packages are automatically installed, such as Arduino Sketch. – $ scons resource/csdk/stack/samples/arduino/SimpleClientServer/ TARGET_OS=arduino TARGET_ARCH=arm BOARD=arduino_due_x TARGET_TRANSPORT=IP SHIELD=WIFI UPLOAD=true -j8 4. Test – $ cd out/linux/x86_64/release/resource/examples – $ ./simpleclient

Embedded Software Lab. @ SKKU