add new qloud-c-sdk component

This commit is contained in:
mculover666
2022-03-25 10:06:56 +08:00
parent 565cd29e94
commit a3ac2e56d8
166 changed files with 35027 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_cos.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-26
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-26 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_COS_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_COS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Cos download params.
*
*/
typedef struct {
const char *url; /**< cos url, user space */
uint32_t offset; /**< download offset */
uint32_t file_size; /**< download file size */
int is_fragmentation; /**< http fragmentation support */
int is_https_enabled; /**< TODO:https support */
} IotCosDownloadParams;
/**
* @brief Init cos download handle.
*
* @param[in] params @see IotCosDownloadParams
* @return pointer to cos download handle
*/
void *IOT_COS_DownloadInit(IotCosDownloadParams *params);
/**
* @brief Fetch data from cos.
*
* @param[in,out] handle pointer to cos download handle, @see HTTPCosDownloadHandle
* @param[out] buf buffer to store data
* @param[in] buf_len buffer length
* @param timeout_ms timeout for fetching
* @return >= 0 for recv data len. others @see IotReturnCode
*/
int IOT_COS_DownloadFetch(void *handle, uint8_t *buf, uint32_t buf_len, uint32_t timeout_ms);
/**
* @brief Is download finished.
*
* @param[in,out] handle pointer to cos download handle, @see HTTPCosDownloadHandle
* @return true for finished
*/
int IOT_COS_DownloadIsFinished(void *handle);
/**
* @brief Deinit cos download.
*
* @param[in,out] handle pointer to cos download handle, @see HTTPCosDownloadHandle
*/
void IOT_COS_DownloadDeinit(void *handle);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_COS_H_

View File

@@ -0,0 +1,52 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_cos.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-26
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-26 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_DYNREG_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_DYNREG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief dynreg device, get device secret or device cert file and private key file from iot platform
*
* @param[in] params @see DeviceInfo
* @return 0 is success other is failed
*/
int IOT_DynReg_Device(DeviceInfo *device_info);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_DYNREG_H_

View File

@@ -0,0 +1,157 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_http_client.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-25
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-25 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_CLIENT_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_CLIENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "qcloud_iot_common.h"
/**
* @brief HTTP write socket timeout.
*
*/
#define HTTP_WRITE_TIMEOUT_MS 5000
/**
* @brief HTTPs read tls timeout.
*
*/
#define HTTPS_READ_TIMEOUT_MS 2000
/**
* @brief Connect params set by user.
*
*/
typedef struct {
const char *url; /**< http header */
const char *port; /**< content length(optional) */
const char *ca_crt; /**< content type(optional) */
} IotHTTPConnectParams;
/**
* @brief Http method.
*
*/
typedef enum {
IOT_HTTP_METHOD_GET = 0,
IOT_HTTP_METHOD_POST,
IOT_HTTP_METHOD_PUT,
IOT_HTTP_METHOD_DELETE,
IOT_HTTP_METHOD_HEAD,
} IotHTTPMethod;
/**
* @brief Request params set by user.
* @ref https://datatracker.ietf.org/doc/html/rfc7231
*
*/
typedef struct {
const char *url; /**< request url */
IotHTTPMethod method; /**< request method */
char *header; /**< http header */
int content_length; /**< content length(optional) */
char *content_type; /**< content type(optional) */
char *content; /**< content (optional) */
} IotHTTPRequestParams;
/**
* @brief Malloc http client.
*
* @return pointer to http client
*/
void *IOT_HTTP_Init(void);
/**
* @brief Free http client.
*
*/
void IOT_HTTP_Deinit(void *client);
/**
* @brief Connect http server.
*
* @param[in,out] client pointer to http client
* @param[in] params params needed to connect http server, @see IotHTTPConnectParams
* @return 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Connect(void *client, IotHTTPConnectParams *params);
/**
* @brief Request http server.
*
* @param[in,out] client pointer to http client
* @param[in] params params needed to send request to http server, @see IotHTTPRequestParams
* @return 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Request(void *client, IotHTTPRequestParams *params);
/**
* @brief Send data to http server.
*
* @param[in,out] client pointer to http client
* @param[in] data data to send
* @param[out] data_len data len
* @return 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Send(void *client, uint8_t *data, int data_len);
/**
* @brief Recv data from http server.
*
* @param[in,out] client pointer to http client
* @param[out] buf buffer to store recv data
* @param[in] buf_len buffer len
* @param timeout_ms timeout for recv
* @return >= 0 for recv data len. others @see IotReturnCode
*/
int IOT_HTTP_Recv(void *client, uint8_t *buf, int buf_len, uint32_t timeout_ms);
/**
* @brief Check is recv finished.
*
* @param[in,out] client pointer to http client
* @return true for finished.
*/
int IOT_HTTP_IsRecvFinished(void *client);
/**
* @brief Disconnect http server.
*
* @param[in,out] client pointer to http client
*/
void IOT_HTTP_Disconnect(void *client);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_CLIENT_H_

View File

@@ -0,0 +1,61 @@
/**
* @file qcloud_iot_http_signed.h
* @author {hubert} ({hubertxxu@tencent.com})
* @brief
* @version 1.0
* @date 2022-01-17
*
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @par Change Log:
* <table>
* Date Version Author Description
* 2022-01-17 1.0 hubertxxu first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_SIGNED_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_SIGNED_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "qcloud_iot_common.h"
typedef struct {
const char *host;
const char *uri;
char *secretkey;
uint32_t recv_timeout_ms;
bool need_recv;
} HttpSignedParams;
/**
* @brief post message and recv response
*
* @param params @see HttpSignedParams
* @param request_buf request buffer
* @param request_buf_len request buffer length
* @param response_buf response buffer if need recv
* @param response_buf_len response buffer length if need recv
* @return int 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Signed_Request(HttpSignedParams *params, const char *request_buf, size_t request_buf_len,
uint8_t *response_buf, int response_buf_len);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_SIGNED_H_

View File

@@ -0,0 +1,119 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_log_upload.h
* @brief
* @author hubertxxu (hubertxxu@tencent.com)
* @version 1.0
* @date 2022-01-05
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2022-01-05 <td>1.0 <td>hubertxxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_LOG_UPLOAD_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_LOG_UPLOAD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
#include "utils_json.h"
#include "utils_hmac.h"
/**
* @brief user callback for saving/reading logs into/from NVS(files/FLASH) after
* upload fail/recover
*/
// callback for saving logs into NVS(files/FLASH) after upload fail
typedef size_t (*LogSaveFunc)(const char *filename, const char *msg, size_t wLen);
// callback for reading logs from NVS(files/FLASH) when upload ready
typedef size_t (*LogReadFunc)(const char *filename, char *buff, size_t rLen);
// callback for deleting logs in NVS(files/FLASH). return 0 when success
typedef int (*LogDelFunc)(const char *filename);
// callback for reading the size of logs in NVS(files/FLASH). return 0 when
// nothing exist
typedef size_t (*LogGetSizeFunc)(const char *filename);
/**
* @brief data structure to init feature of log upload
*/
typedef struct {
/* device info */
const char *product_id;
const char *device_name;
/* auth key, use device secret for PSK device and cert file path for cert device */
const char *sign_key;
/* http connect domain */
const char *host;
uint32_t log_buffer_size;
/* user callback saving/reading logs into/from NVS(files/FLASH) */
const char *save_log_filename;
LogSaveFunc save_func;
LogReadFunc read_func;
LogDelFunc del_func;
LogGetSizeFunc get_size_func;
} LogUploadInitParams;
#define DEFAULT_LOG_UPLOAD_INIT_PARAMS \
{ \
NULL, NULL, NULL, NULL, LOG_UPLOAD_BUFFER_SIZE, NULL, NULL, NULL, NULL, NULL \
}
/**
* @brief append need report log to log upload buffer
*
* @param[in] log_content data of need to report
*/
void IOT_Log_Upload_AppendToUploadBuffer(int log_level, const char *log_content);
/**
* @brief init log upload module
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Log_Upload(bool force_upload);
/**
* @brief init log upload previously
*
* @param[in] init_params @see LogUploadInitParams
* @return @see IotReturnCode
*/
int IOT_Log_Upload_InitPre(LogUploadInitParams *init_params);
/**
* @brief init log upload module
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Log_Upload_Init(void *client);
/**
* @brief stop log upload add release resources
*
* @return @see IotReturnCode
*/
int IOT_Log_Upload_Deinit(void);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_LOG_UPLOAD_H_

View File

@@ -0,0 +1,337 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_mqtt_client.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-05-28
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-05-28 <td>1.0 <td>fancyxu <td>first commit
* <tr><td>2021-07-07 <td>1.1 <td>fancyxu <td>support user host for unittest
* <tr><td>2021-07-08 <td>1.1 <td>fancyxu <td>fix code standard of IotReturnCode and QcloudIotClient
* <tr><td>2021-07-18 <td>1.1 <td>fancyxu <td>fix code standard of pClient
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_MQTT_CLIENT_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_MQTT_CLIENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Max size of a topic name
*
*/
#define MAX_SIZE_OF_CLOUD_TOPIC ((MAX_SIZE_OF_DEVICE_NAME) + (MAX_SIZE_OF_PRODUCT_ID) + 64 + 6)
/**
* @brief MQTT event type
*
*/
typedef enum {
MQTT_EVENT_UNDEF = 0, /**< MQTT undefined event */
MQTT_EVENT_DISCONNECT = 1, /**< MQTT disconnect */
MQTT_EVENT_RECONNECT = 2, /**< MQTT reconnect */
MQTT_EVENT_SUBSCRIBE_SUCCESS = 3, /**< MQTT subscribe success */
MQTT_EVENT_SUBSCRIBE_TIMEOUT = 4, /**< MQTT subscribe timeout */
MQTT_EVENT_SUBSCRIBE_NACK = 5, /**< MQTT subscribe fail */
MQTT_EVENT_UNSUBSCRIBE_SUCCESS = 6, /**< MQTT unsubscribe success */
MQTT_EVENT_UNSUBSCRIBE_TIMEOUT = 7, /**< MQTT unsubscribe timeout */
MQTT_EVENT_UNSUBSCRIBE_NACK = 8, /**< MQTT unsubscribe fail */
MQTT_EVENT_PUBLISH_SUCCESS = 9, /**< MQTT publish success */
MQTT_EVENT_PUBLISH_TIMEOUT = 10, /**< MQTT publish timeout */
MQTT_EVENT_PUBLISH_NACK = 11, /**< MQTT publish fail */
MQTT_EVENT_PUBLISH_RECEIVED = 12, /**< MQTT received msg from server */
MQTT_EVENT_CLIENT_DESTROY = 13, /**< MQTT client destroy */
MQTT_EVENT_UNSUBSCRIBE = 14, /**< MQTT unsubscribe */
MQTT_EVENT_GATEWAY_SEARCH = 15,
} MQTTEventType;
/**
* @brief MQTT event message
*
*/
typedef struct {
MQTTEventType event_type; /**< MQTT event type */
void *msg;
} MQTTEventMsg;
/**
* @brief Define MQTT callback when MQTT event happen
*
* @param[in,out] client pointer to mqtt client
* @param[in] context user callback context, @see MQTTEventHandler
* @param[in] msg the event message @see MQTTEventMsg
*/
typedef void (*MQTTEventHandleFun)(void *client, void *context, MQTTEventMsg *msg);
/* The structure of MQTT event handle */
/**
* @brief Define structure to handle mqtt event
*
*/
typedef struct {
MQTTEventHandleFun h_fp;
void *context;
} MQTTEventHandler;
/**
* @brief return next host ip
*/
typedef char *(*MQTTGetNextHostIp)(void);
/**
* @brief The structure of MQTT init parameters
*
*/
typedef struct {
DeviceInfo *device_info; /**< device info */
const char *host; /**< host for user, null for default using QCLOUD_IOT_MQTT_DIRECT_DOMAIN */
const char *backup_host; /**< backup host for user if host not connect will try use this */
uint32_t command_timeout; /**< timeout value (unit: ms) for MQTT connect/pub/sub/yield */
uint32_t keep_alive_interval_ms; /**< MQTT keep alive time interval in millisecond */
uint8_t clean_session; /**< flag of clean session, 1 clean, 0 not clean */
uint8_t auto_connect_enable; /**< flag of auto reconnection, 1 is enable and recommended */
uint8_t connect_when_construct; /**< 1 is enable when no using pre-process before connect */
uint8_t default_subscribe; /**< 1 is enable when clean session is 0, no subscribe packet send, only add subhandle */
MQTTGetNextHostIp get_next_host_ip; /**< get host ip*/
MQTTEventHandler event_handle; /**< event callback */
} MQTTInitParams;
/**
* Default MQTT init parameters
*/
#define DEFAULT_MQTT_INIT_PARAMS \
{ \
NULL, NULL, NULL, 5000, 240 * 1000, 1, 1, 1, 0, NULL, { 0 } \
}
/**
* @brief MQTT Quality of Service level
*
*/
typedef enum {
QOS0 = 0, /**< At most once delivery */
QOS1 = 1, /**< At least once delivery, PUBACK is required */
QOS2 = 2 /**< Exactly once delivery. NOT supported currently */
} QoS;
/**
* @brief MQTT message parameter for pub/sub
*
*/
typedef struct {
QoS qos; // MQTT QoS level
uint8_t retain; // RETAIN flag
uint8_t dup; // DUP flag
uint16_t packet_id; // MQTT Id
char *topic_name; // MQTT topic
int topic_len; // topic length
union {
uint8_t *payload; // MQTT msg payload
char *payload_str; // MQTT msg payload string
};
int payload_len; // MQTT length of msg payload
} MQTTMessage;
/**
* @brief Params needed to publish expcept topic name(as a paramter of function).
*
*/
typedef struct {
QoS qos; // MQTT QoS level
uint8_t retain; // RETAIN flag
uint8_t dup; // DUP flag
void *payload; // MQTT msg payload
int payload_len; // MQTT length of msg payload
} PublishParams;
/**
* @brief Default MQTT publish params
*
*/
#define DEFAULT_PUB_PARAMS \
{ \
QOS0, 0, 0, NULL, 0 \
}
/**
* @brief Define MQTT SUBSCRIBE callback when message arrived
*
* @param[in,out] client pointer to mqtt client
* @param[in] message publish message from server
* @param[in] usr_data user data of SubscribeParams, @see SubscribeParams
*/
typedef void (*OnMessageHandler)(void *client, const MQTTMessage *message, void *usr_data);
/**
* @brief Define MQTT SUBSCRIBE callback when event happened
*
* @param[in,out] client pointer to mqtt client
* @param[in] event_type @see MQTTEventType
* @param[in] usr_data user data of SubscribeParams, @see SubscribeParams
*
* @return none
*/
typedef void (*OnSubEventHandler)(void *client, MQTTEventType event_type, void *usr_data);
/**
* @brief Define structure to do MQTT subscription
*
*/
typedef struct {
QoS qos; /**< MQTT QoS level */
OnMessageHandler on_message_handler; /**< callback when message arrived */
OnSubEventHandler on_sub_event_handler; /**< callback when event happened */
void *user_data; /**< user context for callback */
void (*user_data_free)(void *); /**< user data free when sub handle remove */
} SubscribeParams;
/**
* Default MQTT subscribe parameters
*
*/
#define DEFAULT_SUB_PARAMS \
{ \
QOS0, NULL, NULL, NULL, NULL \
}
/**
* @brief Create MQTT client and connect to MQTT server.
*
* @param[in] params MQTT init parameters
* @return a valid MQTT client handle when success, or NULL otherwise
*/
void *IOT_MQTT_Construct(const MQTTInitParams *params);
/**
* @brief Connect Mqtt server if not connect.
*
* @param[in,out] client pointer to mqtt client pointer, should using the pointer of IOT_MQTT_Construct return.
* @return @see IotReturnCode
*/
int IOT_MQTT_Connect(void *client);
/**
* @brief Close connection and destroy MQTT client.
*
* @param client pointer to mqtt client pointer
* @return @see IotReturnCode
*/
int IOT_MQTT_Destroy(void **client);
/**
* @brief Check connection and keep alive state, read/handle MQTT packet in synchronized way.
*
* @param[in,out] client pointer to mqtt client
* @param[in] timeout_ms timeout value (unit: ms) for this operation
* @return QCLOUD_RET_SUCCESS when success, QCLOUD_ERR_MQTT_ATTEMPTING_RECONNECT when try reconnecting, others @see
* IotReturnCode
*/
int IOT_MQTT_Yield(void *client, uint32_t timeout_ms);
/**
* @brief Publish MQTT message.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_name topic to publish
* @param[in] params @see PublishParams
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_MQTT_Publish(void *client, const char *topic_name, const PublishParams *params);
/**
* @brief Subscribe MQTT topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @param[in] params @see SubscribeParams
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_MQTT_Subscribe(void *client, const char *topic_filter, const SubscribeParams *params);
/**
* @brief Unsubscribe MQTT topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to unsubscribe
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_MQTT_Unsubscribe(void *client, const char *topic_filter);
/**
* @brief Check if MQTT topic has been subscribed or not
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @return true already subscribed
* @return false not ready
*/
bool IOT_MQTT_IsSubReady(void *client, const char *topic_filter);
/**
* @brief Get user data in subscribe.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @return NULL or user data
*/
void *IOT_MQTT_GetSubUsrData(void *client, const char *topic_filter);
/**
* @brief Subscribe and wait sub ready.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @param[in] params @see SubscribeParams
* @return @see IotReturnCode
*/
int IOT_MQTT_SubscribeSync(void *client, const char *topic_filter, const SubscribeParams *params);
/**
* @brief Check if MQTT is connected.
*
* @param[in,out] client pointer to mqtt client
* @return true connected
* @return false no connected
*/
bool IOT_MQTT_IsConnected(void *client);
/**
* @brief Get device info using to connect mqtt server.
*
* @param[in,out] client pointer to mqtt client
* @return @see DeviceInfo
*/
DeviceInfo *IOT_MQTT_GetDeviceInfo(void *client);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_MQTT_CLIENT_H_

View File

@@ -0,0 +1,113 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_ota.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-11
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-11 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_OTA_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_OTA_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
#include "utils_json.h"
/**
* @brief OTA report type.
*
*/
typedef enum {
IOT_OTA_REPORT_TYPE_DOWNLOADING = 0,
IOT_OTA_REPORT_TYPE_UPGRADE_BEGIN,
IOT_OTA_REPORT_TYPE_UPGRADE_SUCCESS,
IOT_OTA_REPORT_TYPE_DOWNLOAD_TIMEOUT,
IOT_OTA_REPORT_TYPE_FILE_NOT_EXIST,
IOT_OTA_REPORT_TYPE_AUTH_FAIL,
IOT_OTA_REPORT_TYPE_MD5_NOT_MATCH,
IOT_OTA_REPORT_TYPE_UPGRADE_FAIL,
} IotOTAReportType;
/**
* @brief Callback of OTA.
*
*/
typedef struct {
void (*update_firmware_callback)(UtilsJsonValue version, UtilsJsonValue url, UtilsJsonValue md5sum,
uint32_t file_size, void *usr_data);
void (*report_version_reply_callback)(int result_code, void *usr_data);
} IotOTAUpdateCallback;
/**
* @brief OTA init, subscribe update topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IotOTAUpdateCallback
* @param[in] usr_data usr data used in callback
* @return 0 for success, or err code (<0) @see IotReturnCode
*/
int IOT_OTA_Init(void *client, IotOTAUpdateCallback callback, void *usr_data);
/**
* @brief OTA deinit, unsubscribe update topic.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_OTA_Deinit(void *client);
/**
* @brief Report upgrade progress.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] report_type @see IotOTAReportType
* @param[in] progress progress using in IOT_OTA_REPORT_TYPE_DOWNLOADING
* @param[in] version update firmware version
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_OTA_ReportProgress(void *client, char *buf, int buf_len, IotOTAReportType report_type, int progress,
const char *version);
/**
* @brief Report current firmware version.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] version current firmware version
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_OTA_ReportVersion(void *client, char *buf, int buf_len, const char *version);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_OTA_H_

View File

@@ -0,0 +1,73 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_system.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-07-24
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-07-24 <td>1.0 <td>fancyxu <td>first commit
* <tr><td>2022-01-26 <td>1.1 <td>hubert <td>add serverip
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_SYSTEM_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_SYSTEM_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
#include "utils_json.h"
/**
* @brief Get time from system topic
*
* @param[in,out] client pointer to mqtt client
* @param[out] time time from system topic
* @return @see IotReturnCode
*/
int IOT_Sys_GetTime(void *client, uint32_t *time);
/**
* @brief Get ntp time and set to system.
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Sys_SyncNTPTime(void *client);
/**
* @brief Get serverip from system result topic
*
* @param[in,out] client pointer to mqtt client
* @param[out] server_ip serverip from system result topic
* @return @see IotReturnCode
*/
int IOT_Sys_GetServerIp(void *client, char *server_ip);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_SYSTEM_H_