|
Link Kit C-SDK
4.0.0
|
COAP模块实现, 其中包含了连接到物联网平台和收发数据的API接口 更多...
#include "coap_private.h"#include "core_log.h"#include "core_auth.h"#include "core_string.h"#include "core_sha256.h"#include "aiot_state_api.h"
宏定义 | |
| #define | COAP_SIGN_SRC_FMT "clientId%sdeviceName%sproductKey%stimestamp%s" |
函数 | |
| static int32_t | _coap_message_assemble_header (const coap_message_t *message, uint8_t *buff) |
| static void | _coap_token_iteration (uint8_t *token, uint8_t tkl) |
| static int32_t | _coap_message_parse (coap_handle_t *coap_handle, coap_message_t *coap_message, const uint8_t *buff, uint32_t len) |
| static int32_t | _coap_uri_to_option (const char *uri, coap_option_t *option_array, uint8_t *option_cnt) |
| static int32_t | _coap_malloc_message (aiot_sysdep_portfile_t *sysdep, coap_message_t **msg, uint32_t buff_len) |
| static int32_t | _coap_create_request_message (void *handle, coap_request_method_t method, aiot_coap_msg_type_t msg_type, coap_message_t **request) |
| static int32_t | _coap_create_empty_message (void *handle, aiot_coap_msg_type_t type, uint32_t msgid, coap_message_t **empty) |
| static int32_t | _coap_add_option (coap_handle_t *coap_handle, coap_message_t *message, uint16_t opt_num, uint8_t *opt_data, uint32_t opt_len) |
| static int32_t | _coap_connect (void *handle) |
| static int32_t | _coap_send_message (void *handle, coap_message_t *coap_message, uint8_t *payload, uint32_t payload_len) |
| static int32_t | _cal_auth_payload_buff (coap_message_t *coap_message, uint8_t **auth_payload) |
| static int32_t | _send_coap_auth_msg (coap_handle_t *coap_handle, coap_message_t *message, uint32_t auth_info_len) |
| static void | _coap_release_message (void *handle, coap_message_t *message) |
| static uint32_t | _token_str2uint32 (aiot_sysdep_portfile_t *sysdep, uint8_t *token, uint8_t token_len) |
| static int32_t | _coap_recv_message_handler (coap_handle_t *coap_handle, coap_message_t *message, coap_request_cache_t *auth_req_cache) |
| static int32_t | _coap_recv (void *handle, coap_request_cache_t *auth_req_cache) |
| static int32_t | _coap_auth_response_handler (void *handle, const coap_message_t *response, void *user_data) |
| static int32_t | is_content_format_supported (aiot_coap_content_format_t format) |
| void * | aiot_coap_init (void) |
| 初始化coap实例并设置默认参数 更多... | |
| int32_t | aiot_coap_setopt (void *handle, aiot_coap_option_t option, void *data) |
| 设置coap参数 更多... | |
| int32_t | aiot_coap_auth (void *handle) |
| 让coap模块与服务器通信, 并且获取auth token 更多... | |
| int32_t | aiot_coap_send (void *handle, const char *uri, aiot_coap_request_t *request) |
| 发送COAP报文 更多... | |
| int32_t | aiot_coap_recv (void *handle) |
| 从网络收取COAP报文 更多... | |
| int32_t | aiot_coap_deinit (void **handle) |
| 释放COAP实例句柄的资源 更多... | |
COAP模块实现, 其中包含了连接到物联网平台和收发数据的API接口
| #define COAP_SIGN_SRC_FMT "clientId%sdeviceName%sproductKey%stimestamp%s" |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |

|
static |

|
static |
|
static |
|
static |

|
static |
|
static |

|
static |
|
static |
|
static |

|
static |

|
static |
|
static |
| void* aiot_coap_init | ( | void | ) |
初始化coap实例并设置默认参数
| 非NULL | COAP实例句柄 |
| NULL | 初始化失败, 一般是内存分配失败导致 |

| int32_t aiot_coap_setopt | ( | void * | handle, |
| aiot_coap_option_t | option, | ||
| void * | data | ||
| ) |
设置coap参数
下面列出常用的配置选项, 至少需要配置以下选项才可使用COAP的基本功能
其余配置选项均设有默认值, 可按业务需要进行调整
AIOT_COAPOPT_HOST: 配置连接的阿里云COAP站点地址AIOT_COAPOPT_PORT: 配置连接的阿里云COAP站点端口号AIOT_COAPOPT_PRODUCT_KEY: 配置设备的 productKeyAIOT_COAPOPT_DEVICE_NAME: 配置设备的 deviceNameAIOT_COAPOPT_DEVICE_SECRET: 配置设备的 deviceSecretAIOT_COAPOPT_NETWORK_CRED: 配置建立COAP连接时的安全凭据AIOT_COAPOPT_RECV_HANDLER: 配置默认的数据接收回调函数AIOT_COAPOPT_EVENT_HANDLER: 配置COAP事件通知回调函数| [in] | handle | COAP句柄 |
| [in] | option | 配置选项, 更多信息请参考aiot_coap_option_t |
| [in] | data | 配置选项数据, 更多信息请参考aiot_coap_option_t |
| <STATE_SUCCESS | 参数设置失败, 更多信息请本文件后面关于错误码的定义 |
| =STATE_SUCCESS | 参数设置成功 |
| int32_t aiot_coap_auth | ( | void * | handle | ) |
让coap模块与服务器通信, 并且获取auth token
| [in] | handle | COAP句柄 |
| STATE_COAP_AUTH_HANDLE_IS_NULL | 获取auth token时coap handle为空 |
| STATE_COAP_AUTH_DEVICE_INFO_MISSING | 获取auth token时设备的三元组为空 |
| STATE_COAP_SIGN_SRC_MALLOC_FAILED | 获取auth token时为计算签名分配内存失败 |
| STATE_COAP_AUTH_TIMEOUT | 获取auth token发生超时, 超过了 AIOT_COAPOPT_AUTH_TIMEOUT 所定义的超时时间 |
| <STATE_SUCCESS的其他其他错误 | 主要是网络有关的, 具体见本文件下面的错误码定义 |
| =STATE_SUCCESS | 获取auth token成功 |

| int32_t aiot_coap_send | ( | void * | handle, |
| const char * | topic, | ||
| aiot_coap_request_t * | message | ||
| ) |
发送COAP报文
| [in] | handle | COAP句柄 |
| [in] | topic | 目标topic |
| [in] | message | 指向要发送报文的内容的指针 |
| STATE_COAP_SEND_HANDLE_IS_NULL | 发送的报文时, coap_handle为空 |
| STATE_COAP_SEND_TOPIC_IS_NULL | 发送的报文时, topic为空 |
| STATE_COAP_SEND_REQUEST_IS_NULL | 发送的报文时, request为空 |
| STATE_COAP_SEND_PAYLOAD_IS_NULL | 发送的报文时, payload为空 |
| STATE_COAP_SEND_WITHOUT_AUTHORIZATION | 发送消息时auth_token还没有获取到 |
| STATE_COAP_SEND_INVALID_MSG_TYPE | 发送消息时, 消息的类型既不是CON, 也不是NON |
| <STATE_SUCCESS的其他错误 | 主要是网络有关的, 具体见本文件下面的错误码定义 |
| STATE_SUCCESS | 发送coap报文成功 |

| int32_t aiot_coap_recv | ( | void * | handle | ) |
从网络收取COAP报文
| [in] | handle | COAP句柄 |
| STATE_COAP_RECV_HANDLE_IS_NULL | 收取网络报文时, coap handle为空 |
| STATE_COAP_RECV_WITHOUT_AUTHORIZATION | 收取网络报文时, auth token还没有获取到 |
| <STATE_SUCCESS的其他错误 | 主要是网络有关的, 具体见本文件下面的错误码定义 |
| STATE_SUCCESS | 收取COAP报文成功 |

| int32_t aiot_coap_deinit | ( | void ** | handle | ) |
释放COAP实例句柄的资源
| [in] | handle | 指向mqtt实例句柄的指针 |
| STATE_SUCCESS | 执行成功 |
1.8.11