Develop on the device
Updated at:
Use the Link SDK for C to connect a communication module to IoT Platform.
Configure the device-side SDK
- Download Link SDK for C V3.0.1.
- Extract the SDK code from the downloaded package. This topic uses Linux operations as an example.
- Run make menuconfig.
- Select ATM Configurations and click Select.
- Select AT HAL Configurations and click Select.
- Configure the following items.
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 - After the configuration is complete, run ./extract.sh to extract the code.
The extracted code is in the output/eng folder.
The following table describes the code in each subdirectory.
Folder Code Content atm AT command sending and receiving module dev_sign Device identity authentication module infra Internal implementation module mqtt MQTT protocol module wrappers HAL integration module - In the wrappers folder, create a file named wrappers.c. This file must implement the following HAL functions.
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 HAL_MutexDestroy(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 HAL_Printf(const char *fmt, ...) int HAL_Snprintf(char *str, const int len, const char *fmt, ...) uint64_t HAL_UptimeMs(void)Download the sample code for the wrappers.c file.
In the sample code, replace the device certificate information with your own.
Note If you do not use the NUCLEO-F103RB communication module development board, setFEATURE_AT_TCP_HAL_SIM800=nduring configuration. In addition, the code in the wrappers.c file must 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]) 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 HAL_MutexDestroy(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 HAL_Printf(const char *fmt, ...) int HAL_Snprintf(char *str, const int len, const char *fmt, ...) uint64_t HAL_UptimeMs(void)
- Integrate the SDK into the IAR project.
Refer to the following figure.
- Run the SDK to perform a test.
Upon successful execution, the following figure shows the local logs on the device.
Log on to the IoT Platform console. You can also view logs of data reported by devices to the cloud for the corresponding instance in the section.
Is this page helpful?