Use Link SDK for C to connect a communication module to IoT Platform.

Configure a device SDK

  1. Download Link SDK 3.0.1 for C.
  2. Extract code from the SDK package. This topic uses Linux as an example.
    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_PLATFORM_HAS_OS=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 code.
      extract.sh

      The code is saved in the output/eng directory.

      output/eng

      The following table lists subdirectories that reside in the output/eng directory.

      Directory Description
      atm Includes code that you can use to send and receive AT commands.
      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 Message Queuing Telemetry Transport (MQTT) protocol.
      wrappers Includes code that you can use to implement hardware abstraction layer (HAL) functions.
    6. In the wrappers directory, create the wrappers.c file. 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_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN])
      int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN])
      int HAL_GetFirmwareVersion(char *version)
      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 ls_osa_mutex_destroy(void *mutex)
      void HAL_MutexLock(void *mutex)
      void HAL_MutexUnlock(void *mutex)
      
      void *HAL_SemaphoreCreate(void)
      void HAL_SemaphoreDestroy(void *sem)
      void HAL_SemaphorePost(void *sem)
      int HAL_SemaphoreWait(void *sem, uint32_t timeout_ms)
      int HAL_ThreadCreate(void **thread_handle,
                           void *(*work_routine)(void *),
                           void *arg,
                           hal_os_thread_param_t *hal_os_thread_param,
                           int *stack_used)
      
      void HAL_SleepMs(uint32_t ms)
      void ls_osa_print(const char *fmt, ...)
      int HAL_Snprintf(char *str, const int len, const char *fmt, ...)
      uint64_t HAL_UptimeMs(void)

      Download a sample wrappers.c file.

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

      certificate information
      Note If you are not using the NUCLEO-F103RB demo board, set FEATURE_AT_TCP_HAL_SIM800=n. You also need to implement the following HAL functions in the wrappers.c file.
      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])
      int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN])
      int HAL_GetFirmwareVersion(char *version)
      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 ls_osa_mutex_destroy(void *mutex)
      void HAL_MutexLock(void *mutex)
      void HAL_MutexUnlock(void *mutex)
      
      void *HAL_SemaphoreCreate(void)
      void HAL_SemaphoreDestroy(void *sem)
      void HAL_SemaphorePost(void *sem)
      int HAL_SemaphoreWait(void *sem, uint32_t timeout_ms)
      int HAL_ThreadCreate(void **thread_handle,
                           void *(*work_routine)(void *),
                           void *arg,
                           hal_os_thread_param_t *hal_os_thread_param,
                           int *stack_used)
      
      void HAL_SleepMs(uint32_t ms)
      void ls_osa_print(const char *fmt, ...)
      int HAL_Snprintf(char *str, const int len, const char *fmt, ...)
      uint64_t HAL_UptimeMs(void)
                                          
  3. Add the file to the IAR project.
    IAR project
  4. Run the project to perform a test.
    After the project is completed, the following figure shows device logs.device logs

    In the IoT Platform console, choose Maintenance > Device Log. The Device Log page also shows logs that are generated each time the device reports data to IoT Platform.