C-Link SDK FAQ

Updated at:

This topic covers common issues and solutions for compiling versions 3.x and 2.3.0 of the C-Link SDK.

Background

If you have not yet connected to IoT Platform, use the latest version of the SDK. For more information, see Overview.

Important

Due to product strategy adjustments, IoT Platform has stopped developing and updating new features for the C Link SDK. The current SDK version is relatively dated. The SDK does not provide Keil project examples for specific hardware models such as STM32F103C8T6. Issues related to hardware porting failures, compilation errors, and incompatibility between self-built CMSIS_RTOS_V2 projects and earlier SDK versions must be resolved independently by the device side. IoT Platform does not provide technical support or solutions for these hardware-specific issues.

Compiling the SDK with Make

  1. Write a compilation configuration file.

    Note

    If you use Ubuntu or another Linux distribution, you can skip this step and use the default configuration file included with the SDK.

    1. Write the configuration file based on the example in the documentation. For more information, see Make-based cross-compilation example.

    2. Save the configuration file to the src/board directory.

  2. Run a command to select and apply the configuration file.

    1. In the root directory of the SDK, run the make reconfig command.

    2. Enter the number for the desired config.*.* file for your environment and press Enter.

    Selecting the config.ubuntu.x86 file in an Ubuntu environment produces the following log:

    $ make reconfig
    SELECT A CONFIGURATION:
    1) config.esp8266.aos    4) config.mk3080.aos    7) config.win7.mingw32
    2) config.macos.x86    5) config.rhino.make    8) config.xboard.make
    3) config.mk3060.aos    6) config.ubuntu.x86
    #? 6
    SELECTED CONFIGURATION:
    VENDOR :   ubuntu
    MODEL  :   x86
    CONFIGURE .............................. [examples]
    CONFIGURE .............................. [src/infra/log]
    CONFIGURE .............................. [src/infra/system]
    CONFIGURE .............................. [src/infra/utils]
    CONFIGURE .............................. [src/protocol/alcs]
    CONFIGURE .............................. [src/protocol/coap/cloud]
    CONFIGURE .............................. [src/protocol/coap/local]
    CONFIGURE .............................. [src/protocol/http]
    CONFIGURE .............................. [src/protocol/http2]
    CONFIGURE .............................. [src/protocol/mqtt]
    CONFIGURE .............................. [src/ref-impl/hal]
    CONFIGURE .............................. [src/ref-impl/tls]
    CONFIGURE .............................. [src/sdk-impl]
    CONFIGURE .............................. [src/services/awss]
    CONFIGURE .............................. [src/services/dev_bind]
    CONFIGURE .............................. [src/services/http2_stream]
    CONFIGURE .............................. [src/services/linkkit/cm]
    CONFIGURE .............................. [src/services/linkkit/dev_reset]
    CONFIGURE .............................. [src/services/linkkit/dm]
    CONFIGURE .............................. [src/services/mdal/mal]
    CONFIGURE .............................. [src/services/mdal/sal]
    CONFIGURE .............................. [src/services/ota]
    CONFIGURE .............................. [src/services/shadow]
    CONFIGURE .............................. [src/services/subdev]
    CONFIGURE .............................. [src/tools/linkkit_tsl_convert]
    BUILDING WITH EXISTING CONFIGURATION:
    VENDOR :   ubuntu
    MODEL  :   x86
    Components: 
    . examples                                          
    . src/ref-impl/tls                                          
    . src/ref-impl/hal                                          
    . src/tools/linkkit_tsl_convert                                          
    . src/protocol/mqtt                                          
    . src/protocol/http                                          
    . src/protocol/coap/local                                          
    . src/protocol/coap/cloud                                          
    . src/protocol/http2                                          
    . src/protocol/alcs                                          
    . src/infra/system                                          
    . src/infra/utils                                          
    . src/infra/log                                          
    . src/services/shadow                                          
    . src/services/http2_stream                                          
    . src/services/dev_bind                                          
    . src/services/linkkit/cm                                          
    . src/services/linkkit/dm                                          
    . src/services/linkkit/dev_reset                                          
    . src/services/subdev                                          
    . src/services/mdal/mal                                          
    . src/services/mdal/sal                                          
    . src/services/ota                                          
    . src/services/awss                                          
    . src/sdk-impl
  3. Use the menuconfig tool to configure options.

    1. In the root directory of the SDK, run the make menuconfig command.

    2. In the menuconfig tool, select the components you want to configure.

    3. Select Save to save the configuration.

    4. Press the Esc key twice to exit the menuconfig tool.

  4. In the root directory of the SDK, run the make command to compile the SDK.

Successful compilation output

After a successful compilation, a table similar to the following appears. It summarizes resource usage, such as ROM and static RAM, for each module.

Note

The data in the following example is for reference only. The actual data may vary.

| RATE  | MODULE NAME                         | ROM       | RAM       | BSS        | DATA   |
|-------|-------------------------------------|-----------|-----------|------------|--------|
| 27.5% | src/services/linkkit/dm             | 58954     | 172       | 160        | 12     |
| 19.5% | src/protocol/alcs                   | 41961     | 213       | 189        | 24     |
| 11.3% | src/infra/utils                     | 24335     | 284       | 264        | 20     |
| 10.3% | src/services/awss                   | 22253     | 1012      | 1000       | 12     |
| 9.75% | src/protocol/mqtt                   | 20888     | 32        | 20         | 12     |
| 7.95% | src/services/linkkit/cm             | 17026     | 79        | 79         | 0      |
| 4.46% | src/services/ota                    | 9563      | 0         | 0          | 0      |
| 4.10% | src/services/dev_bind               | 8792      | 214       | 214        | 0      |
| 2.24% | src/infra/system                    | 4801      | 1480      | 1404       | 76     |
| 1.75% | src/sdk-impl                        | 3750      | 8         | 8          | 0      |
| 0.62% | src/infra/log                       | 1334      | 268       | 0          | 268    |
| 0.39% | src/services/dev_reset              | 856       | 10        | 10         | 0      |
|-------|-------------------------------------|-----------|-----------|------------|--------|
|  100% | - IN TOTAL -                        | 214513    | 3772      | 3348       | 424    |

Output file location

After compilation, the output files are in the output/release directory.

Key output files

The following directories contain key output files.

  • output/release/lib

    File name

    Description

    libiot_hal.a

    This is a reference implementation of the HAL interface layer. It provides HAL_***() interfaces.

    libiot_sdk.a

    The main library of the SDK. It provides the IOT_*** and linkkit_xxx() interfaces.

    libiot_tls.a

    A trimmed version of Mbed TLS. It provides the mbedtls_*() interface to support libiot_hal.a.

  • output/release/include

    File name

    Description

    iot_import.h

    The underlying support interfaces that you must implement for the SDK.

    iot_export.h

    Underlying programming interfaces that the SDK provides to developers.

  • output/release/bin

    File name

    Description

    linkkit-example-solo

    An advanced example that demonstrates how to use linkkit_***() interfaces.

    mqtt-example

    A basic example that demonstrates how to use IOT_***() interfaces.

Set up the cross-compilation toolchain

You can set up the toolchain for cross-compilation in two ways:

  • Set a prefix for the entire toolchain.

  • Set a prefix for a specific tool.

Open the compilation configuration file src/board/config.*.* and add or modify the toolchain settings by using one of the following methods.

# Example: arm-none-eabi-
# Method 1: Set the toolchain prefix
CROSS_PREFIX        := arm-none-eabi-
# Method 2: Set the prefix for a specific tool
OVERRIDE_CC            :=    arm-none-eabi-gcc
OVERRIDE_LD            :=    arm-none-eabi-ld
OVERRIDE_AR            :=    arm-none-eabi-ar
OVERRIDE_STRIP      :=  arm-none-eabi-strip
# Note: If the cross-compilation toolchain does not have a common prefix or the prefix does not follow the prefix+gcc|ar|strip format, you can use the following code to prevent the strip command from running. For example, armcc does not have a corresponding strip command.
OVERRIDE_STRIP = true

Add compilation and linking options

Open the compilation configuration file src/board/config.*.* and add your options to CONFIG_ENV_CFLAGS and CONFIG_ENV_LDFLAGS. After you add the options, run the make reconfig command to apply the changes.

Compile a dynamic library

In the src/board/config.*.* file, add the CONFIG_LIB_EXPORT := dynamic configuration option. Then, run the make all command. This generates the dynamic library in the output/release/lib/ directory.

Saved menuconfig configuration not loading

menuconfig displays the default configuration each time it is run. To view the details of the last configuration, use the Load feature to load a saved configuration file.

Troubleshoot menuconfig file loading

Files saved with the default configuration name are cleared automatically. Check the name of your saved configuration file. Make sure you have renamed the file and that you are loading it from the correct directory.

Modify SDK configuration options

In the SDK file src/board/config.*.*, add custom CFLAGS using the CONFIG_ENV_CFLAGS += -D***** syntax, where ***** is the macro name of the parameter to override.

The following example shows how to configure parameters, such as the MQTT receive buffer, in the config.*.* file.

CONFIG_ENV_CFLAGS   += \
           -DCONFIG_MQTT_RX_MAXLEN=5000 \
        -DCONFIG_MBEDTLS_DEBUG_LEVEL=0 \

Troubleshoot common menuconfig errors

C-Link SDK v2.3.0 supports menuconfig only in Linux environments. C-Link SDK v3.x supports menuconfig in Linux, macOS, and Windows environments.

  • Windows environment:

    Run the config.bat script.

  • Ubuntu 16.04 desktop environment:

  • Other Linux environments:

    • Check your permissions. If you decompress a file in Windows and then upload it to Linux, permission issues may occur with the tool. To avoid this, download and decompress the source code package directly in your Linux environment.

    • Check the environment variables. Run the following commands to temporarily add these two environment variables.

      export TERMINFO=/usr/share/terminfo
      export TERM=xterm-basic
  • The menuconfig tool does not support C-Link SDK v2.3.0 in non-Linux environments. Instead, to configure the settings, directly modify the corresponding options in the make.settings file.

Exclude modules from compilation

During the cross-compilation porting process, you may need to manually exclude some directories from compilation.

For example, to exclude the examples/ directory and the directory for the default HAL implementation, you can add code in the CONFIG_*****:= format to the src/board/config.*.* file. In this format, ***** represents the path relative to the SDK root directory.

The following code shows how to exclude the modules in the src/ref-impl/tls/ , src/ref-impl/hal/, examples/, and src/tools/linkkit_tsl_convert/ directories.

CONFIG_src/ref-impl/tls         :=
CONFIG_src/ref-impl/hal         :=
CONFIG_examples                 :=
CONFIG_src/tools/linkkit_tsl_convert :=

Extract code from local source

By default, the SDK script downloads code from the cloud for better performance. If you want to extract or trim code from your local files instead, follow these steps:

  • Linux or macOS

    In the C-Link SDK root directory, run the following commands:

    cd c-sdk
    ./extract.sh local
  • Windows

    1. Open the ./config.bat file and change the script command from "%SHELL%" extract.sh to "%SHELL%" extract.sh local.

    2. Double-click ./config.bat to run it.

Enable logging in C-Link SDK v3.x

Logging is disabled by default in C-Link SDK v3.x. Before you compile, enable logging by deselecting the following options in the Log Configurations section.

[ ] MUTE LEVEL of FLOW  (6)
[ ] MUTE LEVEL of DEBUG (5)
[ ] MUTE LEVEL of INFO  (4)
[ ] MUTE LEVEL of WARN  (3)
[ ] MUTE LEVEL of ERROR (2)
[ ] MUTE LEVEL of CRIT  (1)

Device offline status delay

By default, the C-Link SDK's keep-alive interval is set to 1,200 seconds (20 minutes) by the CORE_MQTT_DEFAULT_KEEPALIVE_S configuration option. If you need to change the keep-alive interval, set the MQTT configuration option in the application layer. The following code provides an example:

 uint16_t keepalive = 60; // Data type: (uint16_t *). Value range: 30 to 1200s. Default value: 1200s.
    aiot_mqtt_setopt(mqtt_handle, AIOT_MQTTOPT_KEEPALIVE_SEC, &keepalive);

Set MQTT connection options

Call aiot_mqtt_setopt to set MQTT configuration options. For more information, see aiot_mqtt_option_t.

If the configuration option you need is not listed in aiot_mqtt_option_t, you can find the default SDK configuration options in the /core/utils/core_mqtt.h file.

Important

Do not change these options without careful consideration.

/* default configuration */
#define CORE_MQTT_MODULE_NAME                      "MQTT"
#define CORE_MQTT_DEINIT_INTERVAL_MS               (100)
#define CORE_MQTT_DEFAULT_KEEPALIVE_S              (1200)
#define CORE_MQTT_DEFAULT_CLEAN_SESSION            (1)
#define CORE_MQTT_DEFAULT_CONNECT_TIMEOUT_MS       (10 * 1000)
#define CORE_MQTT_DEFAULT_HEARTBEAT_INTERVAL_MS    (25 * 1000)
#define CORE_MQTT_DEFAULT_HEARTBEAT_MAX_LOST_TIMES (2)
#define CORE_MQTT_DEFAULT_SEND_TIMEOUT_MS          (5 * 1000)
#define CORE_MQTT_DEFAULT_RECV_TIMEOUT_MS          (5 * 1000)
#define CORE_MQTT_DEFAULT_REPUB_TIMEOUT_MS         (3 * 1000)
#define CORE_MQTT_DEFAULT_RECONN_ENABLED           (1)
#define CORE_MQTT_DEFAULT_RECONN_INTERVAL_MS       (2 * 1000)
#define CORE_MQTT_DEFAULT_RECONN_RANDLIMIT_MS      (1 * 1000)
#define CORE_MQTT_DEFAULT_RECONN_MAX_COUNTERS      (60)       /* The maximum number of retries for the MQTT reconnection backoff algorithm. */
#define CORE_MQTT_DEFAULT_DEINIT_TIMEOUT_MS        (2 * 1000)
#define CORE_MQTT_DIAG_TLV_MQTT_CONNECTION         (0x0010)
#define CORE_MQTT_DIAG_TLV_MQTT_HEARTBEAT          (0x0020)
#define CORE_MQTT_NWKSTATS_RTT_THRESHOLD           (10000)
/* default settings for mqtt 5.0 */
#define CORE_TX_PKT_MAX_LENGTH                      (1024 * 256)
#define CORE_DEFAULT_SERVER_RECEIVE_MAX             (10)
#define CORE_MQTT_USER_PROPERTY_KEY_MAX_LEN         (128)  /* max key length for user property */
#define CORE_MQTT_USER_PROPERTY_VALUE_MAX_LEN       (128)  /* max value length for user property */

Connect to MQTT with Username and Password

With the one-type-one-secret authentication method, the pre-registration-free option allows a device to connect to IoT Platform for the first time. The platform automatically creates the device credential and issues a secret to the device. In this scenario, the platform issues a ClientId, Username, and Password instead of a ProductKey, DeviceName, and DeviceSecret.

For this scenario, C-Link SDK v4.x provides three configuration options: AIOT_MQTTOPT_USERNAME, AIOT_MQTTOPT_PASSWORD, and AIOT_MQTTOPT_CLIENTID.

The following code provides an example:

    char *user_name  = "demo_user_name";
    char *password = "demo_passwd";
    char *client_id = "demo_client_id";
    aiot_mqtt_setopt(mqtt_handle, AIOT_MQTTOPT_USERNAME, user_name);
    aiot_mqtt_setopt(mqtt_handle, AIOT_MQTTOPT_PASSWORD, password);
    aiot_mqtt_setopt(mqtt_handle, AIOT_MQTTOPT_CLIENTID, client_id);

Then, call aiot_mqtt_connect to connect the device to IoT Platform.

How do I resolve the "RELRO is not a suffix and its end is not 16KB" error for some SO libraries after upgrading dependencies?

When integrating the SDK on the Android side, if you encounter the error RELRO is not a suffix and its end is not 16KB for some SO libraries after upgrading dependencies, follow these steps:

  1. Upgrade the com.alibaba.ailabs.iot:multiendinonebridge dependency to version 1.0.0.28.3.

  2. Check the APK packaging configuration to ensure that x86 architecture libraries are not included in the final installation package. Keep only the required architectures, such as arm64-v8a.