This section describes how to use the Link SDK for C to connect a communication module to IoT Platform.

Prerequisites

The environment for integrating Link SDK for C is prepared. For more information, see Prepare the environment. This topic uses Linux as an example.

Procedure

  1. Download Link SDK 3.0.1 for C.
  2. Extract code from the SDK package.
    1. Run the make menuconfig command.
    2. Select ATM Configurations and click Select.
      ATM Configurations
    3. Select AT HAL Configurations and click Select.
      AT HAL Configurations
    4. Set the following parameters:
      FEATURE_PLATFORM_HAS_STDINT=y
      FEATURE_INFRA_STRING=y
      FEATURE_INFRA_NET=y
      FEATURE_INFRA_LIST=y
      FEATURE_INFRA_LOG=y
      FEATURE_INFRA_LOG_ALL_MUTED=y
      FEATURE_INFRA_LOG_MUTE_FLW=y
      FEATURE_INFRA_LOG_MUTE_DBG=y
      FEATURE_INFRA_LOG_MUTE_INF=y
      FEATURE_INFRA_LOG_MUTE_WRN=y
      FEATURE_INFRA_LOG_MUTE_ERR=y
      FEATURE_INFRA_LOG_MUTE_CRT=y
      FEATURE_INFRA_TIMER=y
      FEATURE_INFRA_SHA256=y
      FEATURE_INFRA_REPORT=y
      FEATURE_INFRA_COMPAT=y
      FEATURE_DEV_SIGN=y
      FEATURE_MQTT_COMM_ENABLED=y
      FEATURE_MQTT_DEFAULT_IMPL=y
      FEATURE_MQTT_DIRECT=y
      FEATURE_DEVICE_MODEL_CLASSIC=y
      FEATURE_ATM_ENABLED=y
      FEATURE_AT_TCP_ENABLED=y
      FEATURE_AT_PARSER_ENABLED=y
      FEATURE_AT_TCP_HAL_SIM800=y                            
    5. After the configuration is complete, run the ./extract.sh script to extract the code.
      extract.sh

      The code is saved in the output/eng directory.

      ls

      The following table lists the subdirectories that reside in the directory.

      Directory Description
      atm Includes code that you can use to send and receive AT instructions.
      dev_sign Includes code that you can use to authenticate devices.
      infra Includes code that you can use to implement internal functions.
      mqtt Includes code that you can use to implement the MQ Telemetry Transport (MQTT) protocol.
      wrappers Includes code that you can use to implement hardware abstraction layer (HAL) functions.
  3. In the wrappers directory, create a file named wrappers.c. Implement the following HAL functions in the file.
    int32_t HAL_AT_Uart_Deinit(uart_dev_t *uart)
    int32_t HAL_AT_Uart_Init(uart_dev_t *uart)
    int32_t HAL_AT_Uart_Recv(uart_dev_t *uart, void *data, uint32_t expect_size,
    uint32_t *recv_size, uint32_t timeout)
    int32_t HAL_AT_Uart_Send(uart_dev_t *uart, const void *data, uint32_t size,
    uint32_t timeout)
    
    int HAL_GetFirmwareVersion(char *version)
    int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN])
    int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN])
    int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN])
    
    void *HAL_Malloc(uint32_t size)
    void HAL_Free(void *ptr)
    
    void *HAL_MutexCreate(void)
    void HAL_MutexDestroy(void *mutex)
    void HAL_MutexLock(void *mutex)
    void HAL_MutexUnlock(void *mutex)
    
    void HAL_Printf(const char *fmt, ...)
    void HAL_SleepMs(uint32_t ms)
    int HAL_Snprintf(char *str, const int len, const char *fmt, ...)
    uint64_t HAL_UptimeMs(void)

    Click wrapper_nos_demo1.c to download a sample wrappers.c.

    The following figure shows how to specify the certificate information about the serial device in the file.

    wrappers
    Note If you are not using the SIM800C communication module, add the FEATURE_AT_TCP_HAL_SIM800=n statement, and implement the following HAL functions.
    int HAL_AT_CONN_Close(int fd, int32_t remote_port)
    int HAL_AT_CONN_Deinit(void)
    int HAL_AT_CONN_DomainToIp(char *domain, char ip[16])
    int HAL_AT_CONN_Init(void)
    int HAL_AT_CONN_Send(int fd, uint8_t *data, uint32_t len, char remote_ip[16], int32_t remote_port, int32_t timeout)
    int HAL_AT_CONN_Start(at_conn_t *conn)
    
    int32_t HAL_AT_Uart_Deinit(uart_dev_t *uart)
    int32_t HAL_AT_Uart_Init(uart_dev_t *uart)
    int32_t HAL_AT_Uart_Recv(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t *recv_size, uint32_t timeout)
    int32_t HAL_AT_Uart_Send(uart_dev_t *uart, const void *data, uint32_t size, uint32_t timeout)
    
    int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN + 1])
    int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN + 1])
    int HAL_GetFirmwareVersion(char *version)
    int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN + 1])
    
    void *HAL_Malloc(uint32_t size)
    void HAL_Free(void *ptr)
    
    void *HAL_MutexCreate(void)
    void HAL_MutexDestroy(void *mutex)
    void HAL_MutexLock(void *mutex)
    void HAL_MutexUnlock(void *mutex)
    
    void HAL_Printf(const char *fmt, ...)
    void HAL_SleepMs(uint32_t ms)
    int HAL_Snprintf(char *str, const int len, const char *fmt, ...)
    uint64_t HAL_UptimeMs(void)
  4. Add the file to the IAR project.
    The following figure shows the sequence in which the disks are initialized. iot_IAR
  5. Run the project and test data communication.
    After the test is successful, the device logs are displayed, as shown in the following figure. iot_run

    Log on to the IoT Platform console, choose Maintenance > Device Log, and view logs generated when the device reports data to IoT Platform.