Add Thing SDK Embedded

The Thing SDK Embedded is provided as source code in GitHub. In this topic, we explain how to download the source code from GitHub, prepare the build environment, and build the libraries and test programs.

If you use the Thing-IF SDK with the Thing SDK Embedded, skip the steps in this topic.

The source code contains reference implementations for some environments. The reference implementations already include libraries that provide some fundamental features like socket and multi-task support. Please read the sections for the Thing-IF SDK in Thing-IF SDK Structure for more discussion.

Here, we present how to build the reference implementation for Linux. If you want to build programs for other environments, use this topic as a reference to create execution modules.

The KiiThingSDK-Embedded directory created from the download from GitHub includes the gt202, INTEL, MTK, TI, and WinnerMicro directories. See Implementing OS-dependent Processes for more information about those directories.

Preparation

You need the following preparations.

  • Get a GitHub account

    Access the GitHub and create your account.

  • Configure the public key

    While building the SDK, the sub-modules will be automatically downloaded via the SSH connection. You need to create a key pair and register the public key on GitHub for this.

    If the public key is not set, you will get an error when you execute git submodule command.

  • Install the build tools

    Install and configure the build tools like git, gcc, make, Doxygen, and openssl.

The above preparation is not Kii Cloud dependent. Please refer to the information on the Web for the detailed instructions.

Building Libraries

Download the source code from GitHub and build it in the following steps.

  1. Download the Thing SDK Embedded

    In the working directory, execute the following command in the shell to download the SDK.

    $ git clone https://github.com/KiiPlatform/KiiThingSDK-Embedded
    $ cd KiiThingSDK-Embedded
    
  2. Download the submodule

    Download the submodule, kii_json, (described in SDK Structure) with the following commands.

    $ cd kii
    $ git submodule init
    $ git submodule update
    
  3. Build the SDK

    If your environment is Linux, execute the make command under the KiiThingSDK-Embedded directory to build the libkiisdk.so file. You can integrate this file into your program as the SDK library.

    $ make
    

    If your environment is not Linux, use the Makefile for Linux as a reference to build libraries and execution modules.

Building Sample Programs

The Linux directory in the downloaded source code contains sample code. This sample code is handy for testing some fundamental features of the SDK. Please build it as needed.

  1. Change the AppID and other parameters

    The AppID, AppKey, and Site are hard-coded in the source code. Please change them to the values of your application.

    The file to update is Linux/example.h. Find the following three lines in the file at least, and update them to your Kii Cloud application's value. See here to learn how to create a Kii Cloud application and how to find its AppID and other parameters. To learn how these constants are used in the SDK initialization, see here.

    const char EX_APP_SITE[] = "US";
    const char EX_APP_ID[] = "01234567";
    const char EX_APP_KEY[] = "0123456789abcdef0123456789abcdef";
    

    Please specify "US", "JP", "CN3", "SG", "EU", or the server URL in the EX_APP_SITE.

    In addition to the above items, the source code has two constants of IDs for testing purposes. Update them according to the sample functions that you want to execute. These constants are used in the functions described in Setting Access Token.

    const char EX_THING_ID[] = "th.396587a00022-51e9-4e11-5eec-07846c59";
    const char EX_ACCESS_TOKEN[] = "PlRI8O54j74Og7OtRnYLHu-ftQYINQwgDRuyhi3rGlQ";
    
  2. Build the sample program

    Execute the make command to build the sample program.

    $ cd ../Linux
    $ make
    
  3. Run some tests

    The executable module exampleapp will be generated in the working directory when the build is done. Please read the source code for the available options.

Including Libraries

Include the kii.h file in all the source files which will use the Thing SDK Embedded.

#include "kii.h"

You can parse JSON because the kii.h file internally includes the kii_json.h file.

Note that you do not need to include the kii.h file nor kii_json.h file if you include the kii_thing_if.h file of the Thing-IF SDK. The kii_thing_if.h file internally includes the kii.h and kii_json.h files.