README.md 10.8 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

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

George Nash's avatar
George Nash committed
154 155 156
At this time there are three versions of the onboarding tool.  The command line C version, the
command line Java version, and the GUI Android version. Both command line versions are identical.
It does not matter which version of the onboarding tool is used.
Larry Sachs's avatar
Larry Sachs committed
157 158 159 160

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

George Nash's avatar
George Nash committed
161
A Java version of the onboarding-tool can be found in `<iotivity-lite>/swig/apps/java_onboarding_tool`
Larry Sachs's avatar
Larry Sachs committed
162 163

Assuming you have already followed the `Building for Linux` or `Building for Windows` build
George Nash's avatar
George Nash committed
164 165
instructions the following commands can be used to build and run the Java version of the onboarding
tool.
Larry Sachs's avatar
Larry Sachs committed
166 167 168 169 170 171 172 173 174 175 176

Linux:

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

Windows

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

George Nash's avatar
George Nash committed
177 178 179 180 181
The Android version of the onboarding tool can be found in
`<iotivity-lite>/swig/apps/oc/android_on_boarding_tool`

It is built and installed using the same instructions as other Android samples documented above.

Larry Sachs's avatar
Larry Sachs committed
182 183 184 185 186 187 188 189 190
### 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.

George Nash's avatar
George Nash committed
191 192 193
The below steps use the command line version of the onboarding tool. The steps for the Android
onboarding tool is very similar but is not described here.

Larry Sachs's avatar
Larry Sachs committed
194 195
### (Step 1) Onboard and Provision the Server

George Nash's avatar
George Nash committed
196 197 198
There are multiple methods to onboard and provision server and client samples.  Below is given one
of the many possible ways the this could be done.

Larry Sachs's avatar
Larry Sachs committed
199
 - start the server sample
George Nash's avatar
George Nash committed
200 201 202
 - start onboarding tool it will print a menu with many option
 - Type `1` **Enter** to _Discover un-owned devices_
 - Type `8` **Enter** to _Take ownership of device_
Larry Sachs's avatar
Larry Sachs committed
203
   - Type `0` **Enter**. If you have multiple unowned devices you will have to select the correct
George Nash's avatar
George Nash committed
204 205
     device from the list.
 - Type `4` **Enter** to _Discover owned devices_ the device you just took ownership of should be
Larry Sachs's avatar
Larry Sachs committed
206
   listed.
George Nash's avatar
George Nash committed
207
 - Type `13` **Enter** to _Provision ACE2_. There are many ways to properly provision the device.
Larry Sachs's avatar
Larry Sachs committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
   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

### (Step 2) Onboard the client
 - start the client sample
 - Type `1` **Enter** to _Discover un-owned devices_
George Nash's avatar
George Nash committed
225
 - Type `8` **Enter** to _Take ownership of device_
Larry Sachs's avatar
Larry Sachs committed
226 227 228 229 230
   - 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
George Nash's avatar
George Nash committed
231
  - Type `12` **Enter** to _Provision pair-wise credentials_
Larry Sachs's avatar
Larry Sachs committed
232 233 234 235
  - 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
George Nash's avatar
George Nash committed
236 237
The samples should be onboarded and provisioned. Restart the server and then the client they should
discover each other and run without difficulty.
Larry Sachs's avatar
Larry Sachs committed
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

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)