README.md 12.3 KB
Newer Older
Larry Sachs's avatar
Larry Sachs committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
IoTivity-Lite Android port
-------------------------------------------------

Getting Started
=================================================
To use this code you will need the following:
  - git version control system
  - IoTivity-lite
  - SWIG
  - Java Development kit.
  - Android SDK
  - Android NDK
  - Gradle build system

The following contains instructions to obtain and run the tools on Linux.

### Get Tools
It can be installed on Ubuntu Linux using the following command.

    sudo apt-get install git make openjdk-8-jdk swig

### Get IoTivity-Lite
Checkout IoTivity-lite git project run the following command to get a anonymous copy of
iotivity-lite.  Checkout the SWIG branch.

    git clone https://gerrit.iotivity.org/gerrit/iotivity-lite
    git checkout -t origin/swig

### Android SDK tools
Download the [Android SDK command line tools](https://developer.android.com/studio#downloads)
run `sdkmanager` found in the `tools/bin` directory to install the platform-tools and Android platform

    ./sdkmanager "platform-tools" "platforms;android-23"

if behind a proxy use the proxy connection options

    ./sdkmanager --proxy=<http|socks> --proxy_host=<host address> --proxy_port=<number> "platform-tools" "platforms;android-23"

### Android NDK
Download Android NDK

https://developer.android.com/ndk/downloads/index.html

Unzip downloaded package.

    cd <NDK>/build/tools
    sudo apt-get install python
    ./make_standalone_toolchain.py --arch <architecture> --api <level> --install-dir <path>

valid values for `--arch`
 - arm
 - arm64
 - x86
 - x86_64

The `make_standalone_toolchain` script only supports api level 16 and newer. We recommend using api
level 23 or newer.

For example:

    ./make_standalone_toolchain.py --arch arm --api 23 --install-dir ~/android-arm-23

Note: running the `make_standalone_toolchain.py` script may print a WARNING stating it is no longer
necessary.  This is expected.  At this time the make files expect the stand alone tool chain.

For further setup see:

https://developer.android.com/ndk/guides/standalone_toolchain.html

### Android Studio (optional)
Developers wishing to use Android Studio can find details here:

[Android Studio](https://developer.android.com/studio)

Building IoTivity-Lite libraries
=================================================
77
To build for Android cd to
Larry Sachs's avatar
Larry Sachs committed
78 79 80

    cd <iotivity-lite>/android/port

81
The Makefile uses then the Android NDK that was installed above.
Larry Sachs's avatar
Larry Sachs committed
82

83
Either set ANDROID_API and ANDROID_BASE in the Makefile or invoke like this:
Larry Sachs's avatar
Larry Sachs committed
84 85 86 87 88

    make NDK_HOME=/opt/android-ndk ANDROID_API=23

Example Usage:

89
    make IPV4=1 DEBUG=1
Larry Sachs's avatar
Larry Sachs committed
90 91 92

or

93
    make NDK_HOME=~/android-arm-23 ANDROID_API=23 IPV4=1 DEBUG=1
Larry Sachs's avatar
Larry Sachs committed
94

95 96
The Make file will build and copy the library files (*.so and *.jar) into the
provided samples.
Larry Sachs's avatar
Larry Sachs committed
97

98 99 100
If developing your own project you may need to manually copy the libraries from
`<iotivity-lite-root>/swig/iotivity-lite-java/libs` to the location expected
by your project.
Larry Sachs's avatar
Larry Sachs committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378

Building and Running Samples
=================================================
All samples have the default out of the box behavior of IoTivity-Lite which means they are are not
onboarded or provisioned.  The default security will prevent the samples from communicating with
one another till onboarding and provisioning has been completed.  See the following section
**Onboarding and Provisioning** for instructions on using the onboarding tool that is part of
iotivity-lite.

A sample server and client can be found in `<iotivity-lite>/swig/apps/<sample>`

Note that gradlew will require a `local.properties` to exist or ANDROID_HOME to be defined.  An
installation of Android Studio should create the `local.properties` file.

example:

    export ANDROID_HOME=~/Android/sdk


To resolve any proxy issues reference [gradle user guide for proxy](https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy)

The server sample is in `android_simple_server/SimpleServer`.  To build and install the sample
execute the following command:

### Method 1
    ./gradlew installDebug

### Method 2
    ./gradlew assembleDebug

To install

    cd app/build/outputs/apk
    adb install app-armeabi-debug.apk

The client sample is in `android_simple_client/SimpleClient`.  To build and install the sample
execute the following command:

### Method 1
    ./gradlew installDebug

### Method 2
    ./gradlew assembleDebug

To install

    cd app/build/outputs/apk
    adb install app-armeabi-debug.apk

Onboarding and Provisioning
=================================================
### Runing the onboarding tool

At this time there are two versions of the onboarding tool.  The C version and the Java version.
The versions are identical. The exception being that the C version is currently built only for
Linux. While the Java version is available for both windows and Linux.  It does not matter which
version of the onboarding tool.

The C version of the onboarding tool can be found in `<iotivity-lite>/port/linux` see Linux build
instructions.

A Java version of the onboarding-tool that will run on Windows or Linux can be found

A sample server and client can be found in `<iotivity-lite>/swig/apps/java_onboarding_tool`

Assuming you have already followed the `Building for Linux` or `Building for Windows` build
instructions the following commands can be used to build and run the onboarding tool.

Linux:

    build-onboarding-tool-lite.sh
    run-onboarding-tool-lite.sh

Windows

    sh build-onboarding-tool-lite.sh
    run-onboarding-tool-lite.cmd

### Simple Step-by-Step guide for onboarding and provisioning

This guide assumes you are starting one discoverable device at a time. Multiple devices can be
discovered and onboarded at the same time however it becomes the responsibility of the user to
figure out which UUID belongs to which device.

Once you have successfully onboarded the samples the first time using the following step-by-step
options feel free to RESET the devices and play around with different provisioning options.

### (Step 1) Onboard and Provision the Server

 - start the server sample
 - start onboarding tool it will print the following menu:

```
    ################################################
    OCF 1.3 Onboarding Tool
    ################################################
    [0] Display this menu
    -----------------------------------------------
    [1] Discover un-owned devices
    [2] Discover owned devices
    -----------------------------------------------
    [3] Take ownership of device (Just-works)
    [4] Provision pair-wise credentials
    [5] Provision ACE2
    -----------------------------------------------
    [6] RESET device
    -----------------------------------------------
    [9] Exit
    ################################################
    
    Select option:
```

 - Type `1` **Enter** to _Discover un-owned devices_ this should display a something similar to
   this

    Discovered unowned device: c3e5c231-9f95-4859-6d11-87f40b1977d5 at:
    [fe80:0000:0000:0000:05a8:81bd:23cf:3882]:59584
    [fe80:0000:0000:0000:05a8:81bd:23cf:3882]:59585

 - Type `3` **Enter** to _Take ownership of device_
   - Type `0` **Enter**. If you have multiple unowned devices you will have to select the correct
     device from the list.  The following should be displayed

    Successfully issued request to perform ownership transfer

 - Type `2` **Enter** to _Discover owned devices_ the device you just took ownership of should be
   listed.
 - Type `5` **Enter** to _Provision ACE2_. There are many ways to properly provision the device.
   This will give instruction for using wildcard provisioning.
   - Type `0` **Enter**. If you have multiple unowned devices you will have to select the correct
     device from the list.
   - Type `1` **Enter** for an _auth-crypt_ ACE
   - Type `1` **Enter** in response to `Enter number of resources in this ACE:`
   - Type `0` **Enter** in response to `Have resource href? [0-No, 1-Yes]:`
   - Type `1` **Enter** in response to `Set wildcard resource? [0-No, 1-Yes]:`
   - Type `2` **Enter** to select the `[2]: All discoverable resources` option
   - Type `0` **Enter** in response to `Enter number of resource types [0-None]:`
   - Type `0` **Enter** in response to `Enter number of interfaces [0-None]`
   - Type `0` **Enter** for CREATE, `1` **Enter** for RETRIEVE, `1` **Enter** for UPDATE, `0`
     **Enter** for DELETE, and `1` **Enter** for NOTIFY.
   - `Successfully issued request to provision ACE` should be printed on the screen upon success

Example output from following the above listed commands:

    Provision ACL2
    My Devices:
    [0]: 33cd6782-00f3-49db-624e-fda26e945c8d


    Select device for provisioning: 0

    Subjects:
    [0]: anon-clear
    [1]: auth-crypt
    [2]: 33cd6782-00f3-49db-624e-fda26e945c8d

    Select subject: 1

    Enter number of resources in this ACE: 1

    Resource properties
    Have resource href? [0-No, 1-Yes]: 0

    Set wildcard resource? [0-No, 1-Yes]: 1
    [1]: All resources
    [2]: All discoverable resources
    [3]: All non-discoverable resources

    Select wildcard resource: 2
    Enter number of resource types [0-None]: 0
    Enter number of interfaces [0-None]0

    Set ACE2 permissions
    CREATE [0-No, 1-Yes]: 0
    RETRIEVE [0-No, 1-Yes]: 1
    UPDATE [0-No, 1-Yes]: 1
    DELETE [0-No, 1-Yes]: 0
    NOTIFY [0-No, 1-Yes]: 1

    Successfully issued request to provision ACE

### (Step 2) Onboard the client
 - start the client sample
 - Type `1` **Enter** to _Discover un-owned devices_
 - Type `3` **Enter** to _Take ownership of device_
   - Type `0` **Enter**. If you have multiple unowned devices you will have to select the correct
     device from the list.
  - Type `2` **Enter** to _Discover owned devices_ the server and client should be listed

### (Step 3) Pair Server and Client
  - Type `4` **Enter** to _Provision pair-wise credentials_
  - Type `0` **Enter** `1` **Enter** to pair the client and server. If you have multiple owned
    devices you will have to select the correct devices from the list.

### (Step 4) Restart and Test
The samples should be onboarded and provisioned. Restart the server and client they should discover
each other and run without difficulty.

Building Custom Android Applications
=================================================
These libraries and examples were built with Android API 23.  When creating a new Android project you
can choose the API level.  In building these examples, the native code libraries were copied to specific
directories in the project.  The project structure is:

```
    project/
    ├──libs/
    |  └── iotivity-lite.jar
    ├──src/
       └── main/
           ├── AndroidManifest.xml
           ├── java/
           └── jniLibs/
               ├── armeabi/
               │   └── libiotivity-lite-jni.so.so
               └── x86-64/
                   └── libiotivity-lite-jni.so.so
```

This structure is reflected in the app `build.gradle` file:

```
    android {
        .
        .
        .
        sourceSets {
            main {
                jniLibs.srcDirs = ["src/main/jniLibs", "$buildDir/native-libs"]
            }
        }
        splits {
            abi {
                enable true
                reset()
                include 'x86_64', 'armeabi'
                universalApk false
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        .
        .
        .
    }
```

To allow these example applications to work, permissions had to be granted in the `AndroidManifest.xml` file.

```
    <manifest ...>
    
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
        <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
        
        <application
            .
            .
            .
        </application>
    
    </manifest>
```

Send Feedback
=================================================
Questions
[IoTivity-Lite Developer Mailing List](https://iotivity-dev@lists.iotivity.org)

Bugs
[Jira bug reporting website](https://jira.iotivity.org/projects/LITE)