Building Sample Programs

Let us download the source code of Hello Thing-IF and build the mobile app and thing program.

You can download the source code from GitHub.

$ git clone https://github.com/KiiPlatform/Hello-Thing-IF-Sample

The download has the following directories:

Directory Description
android_fcm Android mobile app which uses FCM for push notification
android_gcm Android mobile app which uses GCM for push notification
android_jpush Android mobile app which uses JPush for push notification
thing Thing program

Projects for iOS and JavaScript apps are under development.

GCM users are recommended to upgrade to FCM. Select FCM if you are developing a new mobile app. Refer to the directory with GCM to maintain existing mobile apps.

Follow the preparation steps below.

Creating an Application

First, create an application on Kii Cloud. This application will be referenced by both the mobile app and thing program. Various pieces of information such as mobile app users, things, commands, and state information will be managed on the created application.

Go to Create an Application and complete all the steps and return to this topic. In one of the steps, you will check the AppID of the created application. Make a note of those values as you will use them later.

Building the Android Mobile App

Next, build the mobile app for Android.

  1. Open the project in Android Studio

    Launch Android Studio and open the project. Use Android Studio 2.1 or later because the project for Hello Thing-IF was created with Android Studio 2.1.

    Open one of these directories as an Android Studio project according to the push notification service of your choice.

    • FCM: HelloThingIF in android_fcm
    • GCM: HelloThingIF in android_gcm
    • JPush: HelloThingIF in android_jpush
  2. Embed the AppID

    Open HelloThingIF.java and update the following constants:

    public static final String APP_ID = "___APP_ID___";
    public static final String APP_KEY = "___APP_KEY___";
    public static final Kii.Site APP_SITE_CLOUD = Kii.Site.US;
    public static final Site APP_SITE_THING_IF = Site.US;
    

    Specify the AppID in APP_ID and an arbitrary value in APP_KEY. You made a note of these values when you created the application on Kii Cloud.

    Specify the server location in APP_SITE_CLOUD and APP_SITE_THING_IF. You specify it in the two constants because the symbols are different between the Kii Cloud SDK and the Thing-IF SDK. Specify a value which represents the same server location in these constants, such as US, JP, and CN3.

  3. Implement push notification

    Set up the push notification feature so that the mobile app can use it.

    The steps are different among FCM, GCM, and JPush. Complete all the steps in one of the following topics and return to this topic.

  4. Build the mobile app

    The "Sync Now" link will be displayed if the project needs to be synchronized. Click the link to do so and then build the mobile app.

If You Cannot Build the Mobile App

The Hello Thing-IF mobile app was created and built with Android Studio 2.1.

If you cannot build it properly, the root cause is probably using a different environment. Search for resolutions by, for example, checking error messages displayed at build time with any search engine. Especially, carefully check errors in each tab of Android Studio. Errors might not be displayed in tabs in the foreground.

If the problem persists, try using Android Studio 2.1, which is available at the Android Studio Project Site.

Also, verify that you have completed the steps mentioned in the Implement push notification section above.

  • With FCM or GCM, the build fails if the JSON file or the FCM/GCM library is missing in the project. Ensure that the same package name is specified in the FCM/GCM console and Android Studio, too.

  • With JPush, the build fails if the JPush SDK is missing in the project.

Building the Thing Program

Next, build the thing program.

  1. Build the Thing-IF SDK

    Download and build the Thing-IF SDK from GitHub. You can build the thing program of Hello Thing-IF with the default makefile if the source code of the SDK and Hello Thing-IF are placed as in the figure below.

    Go to Add Thing-IF SDK and complete all the steps up to building libkiithingifsdk.so and return to this topic. Skip the remaining steps in the topic.

  2. Embed the AppID

    Open hellothingif.h in the thing directory with any text editor and update the following constants:

    const char EX_APP_ID[] = "___APP_ID___";
    const char EX_APP_KEY[] = "___APP_KEY___";
    const char EX_APP_SITE[] = "___SITE___";
    

    Specify the AppID EX_APP_ID and an arbitrary value in EX_APP_KEY. You made a note of these values when you created the application on Kii Cloud.

    Specify the server location such as US, JP, and CN3 in EX_APP_SITE.

  3. Build the thing program

    Move to the thing directory of Hello Thing-IF and run make. If the SDK directory is not placed as in the above figure, update the SDK_DIR setting in the makefile.

    $ make
    

    The build is successful if the hellothingif file is created in the thing directory.

  4. Set LD_LIBRARY_PATH

    Set the environment variable LD_LIBRARY_PATH as required. For example, run the command as below to link the Thing-IF SDK library libkiithingifsdk.so.

    $ export LD_LIBRARY_PATH=/home/yourname/thing-if-ThingSDK
    

What's Next?

Run the mobile app and the thing program that you built in this topic and try sending commands and state information.

Go to Running Sample Programs.

If you want to learn more...

  • If you plan to develop a new mobile app, see the quick start topics for Android and iOS. The sample programs included in Hello Thing-IF work with the minimum configuration described in this topic.

  • If you plan to develop a new thing program, see Quick Start. Develop your thing program by using the sample program as a reference. You would need to develop OS-dependent processes specific to your target environment.