feat: 移植腾讯云物联网开发平台 C SDK

This commit is contained in:
fancyxu
2022-07-01 11:06:09 +08:00
parent 2be1169b0b
commit 0acc079ed6
195 changed files with 36646 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
/**
* @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_debug.h
* @brief iot debug & upload debug
* @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
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEBUG_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEBUG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "utils_log.h"
#include "qcloud_iot_config.h"
#include "qcloud_iot_platform.h"
#ifdef IOT_DEBUG
#define IOT_FUNC_ENTRY \
{ \
Log_d("FUNC_ENTRY: %s L#%d \n", __FUNCTION__, __LINE__); \
}
#define IOT_FUNC_EXIT \
{ \
Log_d("FUNC_EXIT: %s L#%d \n", __FUNCTION__, __LINE__); \
return; \
}
#define IOT_FUNC_EXIT_RC(x) \
{ \
Log_d("FUNC_EXIT: %s L#%d Return Code : %d \n", __FUNCTION__, __LINE__, x; \
return x; \
}
#else
#define IOT_FUNC_ENTRY
#define IOT_FUNC_EXIT \
{ \
return; \
}
#define IOT_FUNC_EXIT_RC(x) \
{ \
return x; \
}
#endif
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEBUG_H_

View File

@@ -0,0 +1,114 @@
/**
* @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_device.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
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEVICE_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEVICE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_config.h"
/**
* @brief MAX size of client ID.
*
*/
#define MAX_SIZE_OF_CLIENT_ID (80)
/**
* @brief MAX size of product ID.
*
*/
#define MAX_SIZE_OF_PRODUCT_ID (10)
/**
* @brief MAX size of product secret.
*
*/
#define MAX_SIZE_OF_PRODUCT_SECRET (32)
/**
* @brief MAX size of device name.
*
*/
#define MAX_SIZE_OF_DEVICE_NAME (48)
/**
* @brief MAX size of device secret.
*
*/
#define MAX_SIZE_OF_DEVICE_SECRET (64)
/**
* @brief MAX size of device cert file name.
*
*/
#define MAX_SIZE_OF_DEVICE_CERT_FILE_NAME (128)
/**
* @brief MAX size of device key file name.
*
*/
#define MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME (128)
/**
* @brief Max size of base64 encoded PSK = 64, after decode: 64/4*3 = 48.
*
*/
#define MAX_SIZE_OF_DECODE_PSK_LENGTH 48
/**
* @brief Device info needed to connect mqtt server.
*
*/
typedef struct {
char product_id[MAX_SIZE_OF_PRODUCT_ID + 1];
char device_name[MAX_SIZE_OF_DEVICE_NAME + 1];
char client_id[MAX_SIZE_OF_CLIENT_ID + 1];
#ifdef AUTH_MODE_CERT
char dev_cert_file_name[MAX_SIZE_OF_DEVICE_CERT_FILE_NAME + 1];
char dev_key_file_name[MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME + 1];
#else
char device_secret[MAX_SIZE_OF_DEVICE_SECRET + 1];
uint8_t device_secret_decode[MAX_SIZE_OF_DECODE_PSK_LENGTH];
size_t device_secret_decode_len;
#endif
#ifdef DEV_DYN_REG_ENABLED
char product_secret[MAX_SIZE_OF_PRODUCT_SECRET + 1];
#endif
} DeviceInfo;
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEVICE_H_

View File

@@ -0,0 +1,97 @@
/**
* @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_error.h
* @brief error code of sdk
* @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-08 <td>1.1 <td>fancyxu <td>fix code standard of IotReturnCode and QcloudIotClient
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_ERROR_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_ERROR_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IOT SDK return/error code.
* Enumeration of return code in QCloud IoT C-SDK.
* Values less than 0 are specific error codes
* Value of 0 is successful return
* Values greater than 0 are specific non-error return codes
*
*/
typedef enum {
QCLOUD_RET_SUCCESS = 0, /**< Successful return */
QCLOUD_ERR_FAILURE = -1, /**< Generic failure return */
QCLOUD_ERR_INVAL = -2, /**< Invalid parameter */
QCLOUD_ERR_DEV_INFO = -3, /**< Fail to get device info */
QCLOUD_ERR_MALLOC = -4, /**< Fail to malloc memory */
QCLOUD_RET_MQTT_ALREADY_CONNECTED = 4, /**< Already connected with MQTT server */
QCLOUD_RET_MQTT_CONNACK_CONNECTION_ACCEPTED = 3, /**< MQTT connection accepted by server */
QCLOUD_RET_MQTT_MANUALLY_DISCONNECTED = 2, /**< Manually disconnected with MQTT server */
QCLOUD_RET_MQTT_RECONNECTED = 1, /**< Reconnected with MQTT server successfully */
QCLOUD_ERR_MQTT_NO_CONN = -101, /**< Not connected with MQTT server */
QCLOUD_ERR_MQTT_ATTEMPTING_RECONNECT = -102, /**< Reconnecting with MQTT server */
QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT = -103, /**< MQTT reconnect timeout */
QCLOUD_ERR_MQTT_SUB = -104, /**< MQTT topic subscription fail */
QCLOUD_ERR_MQTT_NOTHING_TO_READ = -105, /**< MQTT nothing to read */
QCLOUD_ERR_MQTT_PACKET_READ = -106, /**< Something wrong when reading MQTT packet */
QCLOUD_ERR_MQTT_REQUEST_TIMEOUT = -107, /**< MQTT request timeout */
QCLOUD_ERR_RX_MESSAGE_INVAL = -108, /**< MQTT received invalid msg */
QCLOUD_ERR_BUF_TOO_SHORT = -109, /**< MQTT recv buffer not enough */
QCLOUD_ERR_MQTT_QOS_NOT_SUPPORT = -110, /**< MQTT QoS level not supported */
QCLOUD_ERR_MQTT_UNSUB_FAIL = -111, /**< MQTT unsubscribe failed */
QCLOUD_ERR_MAX_TOPIC_LENGTH = -112, /**< Topic length oversize */
QCLOUD_ERR_HTTP = -201, /**< HTTP unknown error */
QCLOUD_ERR_HTTP_AUTH = -202, /**< HTTP auth failed */
QCLOUD_ERR_HTTP_NOT_FOUND = -203, /**< HTTP 404 */
QCLOUD_ERR_HTTP_TIMEOUT = -204, /**< HTTP timeout */
QCLOUD_ERR_HTTP_PARSE = -205, /**< HTTP URL parse failed */
QCLOUD_ERR_JSON_PARSE = -300, /**< JSON parsing error */
QCLOUD_ERR_TCP_SOCKET_FAILED = -401, /**< TLS TCP socket connect fail */
QCLOUD_ERR_TCP_UNKNOWN_HOST = -402, /**< TCP unknown host (DNS fail) */
QCLOUD_ERR_TCP_CONNECT = -403, /**< TCP/UDP socket connect fail */
QCLOUD_ERR_TCP_READ_TIMEOUT = -404, /**< TCP read timeout */
QCLOUD_ERR_TCP_WRITE_TIMEOUT = -405, /**< TCP write timeout */
QCLOUD_ERR_TCP_READ_FAIL = -406, /**< TCP read error */
QCLOUD_ERR_TCP_WRITE_FAIL = -407, /**< TCP write error */
QCLOUD_ERR_TCP_PEER_SHUTDOWN = -408, /**< TCP server close connection */
QCLOUD_ERR_TCP_NOTHING_TO_READ = -409, /**< TCP socket nothing to read */
QCLOUD_ERR_SSL_INIT = -501, /**< TLS/SSL init fail */
QCLOUD_ERR_SSL_CERT = -502, /**< TLS/SSL certificate issue */
QCLOUD_ERR_SSL_CONNECT = -503, /**< TLS/SSL connect fail */
QCLOUD_ERR_SSL_CONNECT_TIMEOUT = -504, /**< TLS/SSL connect timeout */
QCLOUD_ERR_SSL_WRITE_TIMEOUT = -505, /**< TLS/SSL write timeout */
QCLOUD_ERR_SSL_WRITE = -506, /**< TLS/SSL write error */
QCLOUD_ERR_SSL_READ_TIMEOUT = -507, /**< TLS/SSL read timeout */
QCLOUD_ERR_SSL_READ = -508, /**< TLS/SSL read error */
QCLOUD_ERR_SSL_NOTHING_TO_READ = -509, /**< TLS/SSL nothing to read */
} IotReturnCode;
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_ERROR_H_

View File

@@ -0,0 +1,100 @@
/**
* @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_params_check.h
* @brief check params
* @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
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PARAMS_CHECK_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PARAMS_CHECK_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include "utils_log.h"
#define NUMBERIC_SANITY_CHECK(num, err) \
do { \
if (0 > (num)) { \
Log_e("Invalid argument, numeric 0"); \
return (err); \
} \
} while (0)
#define NUMBERIC_SANITY_CHECK_RTN(num) \
do { \
if (0 > (num)) { \
Log_e("Invalid argument, numeric 0"); \
return; \
} \
} while (0)
#define POINTER_SANITY_CHECK(ptr, err) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, ptr); \
return (err); \
} \
} while (0)
#define POINTER_SANITY_CHECK_RTN(ptr) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, ptr); \
return; \
} \
} while (0)
#define STRING_PTR_SANITY_CHECK(ptr, err) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, (ptr)); \
return (err); \
} \
if (0 == strlen((ptr))) { \
Log_e("Invalid argument, %s = '%s'", #ptr, (ptr)); \
return (err); \
} \
} while (0)
#define STRING_PTR_SANITY_CHECK_RTN(ptr) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, (ptr)); \
return; \
} \
if (0 == strlen((ptr))) { \
Log_e("Invalid argument, %s = '%s'", #ptr, (ptr)); \
return; \
} \
} while (0)
#define STRING_PTR_PRINT_SANITY_CHECK(s) ((s) ? (s) : "null")
#if defined(__cplusplus)
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PARAMS_CHECK_H_

View File

@@ -0,0 +1,451 @@
/**
* @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_platform.h
* @brief hal interface
* @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-09 <td>1.1 <td>fancyxu <td>support tls and change port to str format
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PLATFORM_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PLATFORM_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "qcloud_iot_device.h"
#include "qcloud_iot_common.h"
/**********************************************************************
* QCloud IoT C-SDK Hardware Abstraction Layer
* Platform/OS/IP stack/SSL dependant functions
* Check platform folder for reference implementation
* Require porting when adapt SDK to new platform/OS
*********************************************************************/
/**************************************************************************************
* os
**************************************************************************************/
/**
* @brief Mutex create.
*
* @return pointer to mutex
*/
void *HAL_MutexCreate(void);
/**
* @brief Mutex destroy.
*
* @param[in,out] mutex pointer to mutex
*/
void HAL_MutexDestroy(void *mutex);
/**
* @brief Mutex lock.
*
* @param[in,out] mutex pointer to mutex
*/
void HAL_MutexLock(void *mutex);
/**
* @brief Mutex try lock.
*
* @param[in,out] mutex pointer to mutex
* @return 0 for success
*/
int HAL_MutexTryLock(void *mutex);
/**
* @brief Mutex unlock.
*
* @param[in,out] mutex pointer to mutex
*/
void HAL_MutexUnlock(void *mutex);
/**
* @brief Malloc from heap.
*
* @param[in] size size to malloc
* @return pointer to buffer, NULL for failed.
*/
void *HAL_Malloc(size_t size);
/**
* @brief Free buffer malloced by HAL_Malloc.
*
* @param[in] ptr
*/
void HAL_Free(void *ptr);
/**
* @brief Printf with format.
*
* @param[in] fmt format
*/
void HAL_Printf(const char *fmt, ...);
/**
* @brief Snprintf with format.
*
* @param[out] str buffer to save
* @param[in] len buffer len
* @param[in] fmt format
* @return length of formatted string, >0 for success.
*/
int HAL_Snprintf(char *str, const int len, const char *fmt, ...);
/**
* @brief Sleep for ms.
*
* @param[in] ms ms to sleep
*/
void HAL_SleepMs(uint32_t ms);
#ifdef MULTITHREAD_ENABLED
/**
* @brief Theard entry function.
*
*/
typedef void (*ThreadRunFunc)(void *arg);
/**
* @brief Thread priority.
*
*/
typedef enum {
THREAD_PRIORITY_HIGH,
THREAD_PRIORITY_MIDDLE,
THREAD_PRIORITY_LOW,
} ThreadPriority;
/**
* @brief Thread params to create.
*
*/
typedef struct {
char *thread_name; /**< thread name */
void* thread_id; /**< thread handle */
ThreadRunFunc thread_func; /**< thread entry function */
void *user_arg; /**< thread entry arg */
ThreadPriority priority; /**< thread priority */
void *stack_base; /**< thread stack base */
uint32_t stack_size; /**< thread stack size */
} ThreadParams;
/**
* @brief platform-dependant thread create function
*
* @param[in,out] params params to create thread @see ThreadParams
* @return @see IotReturnCode
*/
int HAL_ThreadCreate(ThreadParams *params);
/**
* @brief platform-dependent thread destroy function.
*
*/
void HAL_ThreadDestroy(void *thread_id);
/**
* @brief platform-dependent semaphore create function.
*
* @return pointer to semaphore
*/
void *HAL_SemaphoreCreate(void);
/**
* @brief platform-dependent semaphore destory function.
*
* @param[in] sem pointer to semaphore
*/
void HAL_SemaphoreDestroy(void *sem);
/**
* @brief platform-dependent semaphore post function.
*
* @param[in] sem pointer to semaphore
*/
void HAL_SemaphorePost(void *sem);
/**
* @brief platform-dependent semaphore wait function.
*
* @param[in] sem pointer to semaphore
* @param[in] timeout_ms wait timeout
* @return @see IotReturnCode
*/
int HAL_SemaphoreWait(void *sem, uint32_t timeout_ms);
/**
* @brief platform-dependent mail queue init function.
*
* @param[in] pool pool using in mail queue
* @param[in] mail_size mail size
* @param[in] mail_count mail count
* @return pointer to mail queue
*/
void *HAL_MailQueueInit(void *pool, size_t mail_size, int mail_count);
/**
* @brief platform-dependent mail queue deinit function.
*
* @param[in] mail_q pointer to mail queue
*/
void HAL_MailQueueDeinit(void *mail_q);
/**
* @brief platform-dependent mail queue send function.
*
* @param[in] mail_q pointer to mail queue
* @param[in] buf data buf
* @param[in] size data size
* @return 0 for success
*/
int HAL_MailQueueSend(void *mail_q, const void *buf, size_t size);
/**
* @brief platform-dependent mail queue send function.
*
* @param[in] mail_q pointer to mail queue
* @param[out] buf data buf
* @param[in] size data size
* @param[in] timeout_ms
* @return 0 for success
*/
int HAL_MailQueueRecv(void *mail_q, void *buf, size_t *size, uint32_t timeout_ms);
#endif
/**
* @brief Functions for saving file into NVS(files/FLASH)
* @param[in] filename file path name
* @param[in] buf source need write buffer
* @param[in] write_len length of file to write
* @return length of data save when success, or 0 for failure
*/
size_t HAL_File_Write(const char *filename, const void *buf, size_t write_len, size_t offset);
/**
* @brief Functions for reading file from NVS(files/FLASH)
* @param[in] filename file path name
* @param[in] buf destination log buffer
* @param[in] read_len length to read
* @return length of data read when success, or 0 for failure
*/
size_t HAL_File_Read(const char *filename, void *buf, size_t read_len, size_t offset);
/**
* @brief Functions for deleting file in NVS(files/FLASH).
* @param[in] filename file path name
* @return 0 when success
*/
int HAL_File_Del(const char *filename);
/**
* @brief Functions for reading the size of file in NVS(files/FLASH).
* @param[in] filename file path name
* @return 0 when nothing exist
*/
size_t HAL_File_GetSize(const char *filename);
/**************************************************************************************
* device info
**************************************************************************************/
/**
* @brief Save device info
*
* @param[in] device_info @see DeviceInfo
* @return @see IotReturnCode
*/
int HAL_SetDevInfo(DeviceInfo *device_info);
/**
* @brief Get device info
*
* @param[in] device_info @see DeviceInfo
* @return @see IotReturnCode
*/
int HAL_GetDevInfo(DeviceInfo *device_info);
/**************************************************************************************
* timer
**************************************************************************************/
/**
* @brief time format string
*
* @return time format string, such as "2021-05-31 15:58:46"
*/
char *HAL_Timer_Current(void);
/**
* @brief Get utc time ms timestamp.
*
* @return timestamp
*/
uint64_t HAL_Timer_CurrentMs(void);
/**
* @brief Set system time using second timestamp
*
* @param[in] timestamp_ms
* @return 0 for success
*/
int HAL_Timer_SetSystimeMs(uint64_t timestamp_ms);
/**************************************************************************************
* network tcp
**************************************************************************************/
/**
* @brief TCP connect in linux
*
* @param[in] host host to connect
* @param[out] port port to connect
* @return socket fd
*/
int HAL_TCP_Connect(const char *host, const char *port);
/**
* @brief TCP disconnect
*
* @param[in] fd socket fd
* @return 0 for success
*/
int HAL_TCP_Disconnect(int fd);
/**
* @brief TCP write
*
* @param[in] fd socket fd
* @param[in] buf buf to write
* @param[in] len buf len
* @param[in] timeout_ms timeout
* @param[out] written_len data written length
* @return @see IotReturnCode
*/
int HAL_TCP_Write(int fd, const uint8_t *data, uint32_t len, uint32_t timeout_ms, size_t *written_len);
/**
* @brief TCP read.
*
* @param[in] fd socket fd
* @param[out] buf buffer to save read data
* @param[in] len buffer len
* @param[in] timeout_ms timeout
* @param[out] read_len length of data read
* @return @see IotReturnCode
*/
int HAL_TCP_Read(int fd, uint8_t *data, uint32_t len, uint32_t timeout_ms, size_t *read_len);
/**************************************************************************************
* AT module
**************************************************************************************/
#ifdef AT_MODULE_ENABLE
/**
* @brief Urc handler.
*
*/
typedef void (*OnUrcHandler)(const char *data, size_t data_len);
/**
* @brief Init at module.
*
* @return 0 for success
*/
int HAL_Module_Init(void);
/**
* @brief Deinit at module.
*
*/
void HAL_Module_Deinit(void);
/**
* @brief Send at cmd to at module and wait for resp.
*
* @param[in] at_cmd at cmd
* @param[in] at_expect expect resp
* @param[in] timeout_ms wait timeout
* @return 0 for success
*/
int HAL_Module_SendAtCmdWaitResp(const char *at_cmd, const char *at_expect, uint32_t timeout_ms);
/**
* @brief Send at cmd and waif for data.
*
* @param[in] at_cmd at cmd
* @param[in] at_expect expect resp
* @param[out] recv_buf recv data buffer
* @param[out] recv_len recv data length
* @param[in] timeout_ms wait timeout
* @return 0 for success
*/
int HAL_Module_SendAtCmdWaitRespWithData(const char *at_cmd, const char *at_expect, void *recv_buf, uint32_t *recv_len,
uint32_t timeout_ms);
/**
* @brief Send date to at module.
*
* @param[in] data data to send
* @param[in] data_len data length
* @return 0 for success
*/
int HAL_Module_SendAtData(const void *data, int data_len);
/**
* @brief Set urc.
*
* @param[in] urc irc string
* @param[in] urc_handler urc handler
* @return 0 for success
*/
int HAL_Module_SetUrc(const char *urc, OnUrcHandler urc_handler);
/**
* @brief connect network
*
* @return int 0 for success
*/
int HAL_Module_ConnectNetwork(void);
#endif
#if defined(__cplusplus)
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PLATFORM_H_

View File

@@ -0,0 +1,88 @@
/**
* @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_timer.h
* @brief timer interface
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2022-04-07
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-04-07 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_TIMER_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_TIMER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "qcloud_iot_platform.h"
/**
* @brief Define timer.
*
*/
#define QcloudIotTimer uint64_t
/**
* @brief Return if timer expired.
*
* @param[in] timer @see QcloudIotTimer
* @return true expired
* @return false no expired
*/
bool IOT_Timer_Expired(QcloudIotTimer *timer);
/**
* @brief Countdown ms.
*
* @param[in,out] timer @see QcloudIotTimer
* @param[in] timeout_ms ms to count down
*/
void IOT_Timer_CountdownMs(QcloudIotTimer *timer, uint32_t timeout_ms);
/**
* @brief Countdown second
*
* @param[in,out] timer @see QcloudIotTimer
* @param[in] timeout second to count down
*/
void IOT_Timer_Countdown(QcloudIotTimer *timer, uint32_t timeout);
/**
* @brief QcloudIotTimer remain ms.
*
* @param[in] timer @see QcloudIotTimer
* @return ms
*/
uint64_t IOT_Timer_Remain(QcloudIotTimer *timer);
/**
* @brief Get current utf timestamp of second
*
* @return timestamp
*/
uint64_t IOT_Timer_CurrentSec(void);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_TIMER_H_

View File

@@ -0,0 +1,55 @@
/**
* @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_config.h
* @brief sdk config define
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-06-01
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-06-01 <td>1.0 <td>fancyxu <td>first commit
* <tr><td>2021-07-12 <td>1.1 <td>fancyxu <td>rename AUTH_WITH_NOTLS to AUTH_WITH_NO_TLS
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_CONFIG_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
/* #undef AUTH_MODE_CERT */
#define AUTH_MODE_KEY
#define AUTH_WITH_NO_TLS
/* #undef GATEWAY_ENABLED */
/* #undef SYSTEM_COMM */
/* #undef DEV_DYN_REG_ENABLED */
/* #undef LOG_UPLOAD */
/* #undef IOT_DEBUG */
#define DEBUG_DEV_INFO_USED
#define AT_MODULE_ENABLE
#define MULTITHREAD_ENABLED
/* #undef LOG_UPLOAD_TYPE_JSON */
/* #undef LOG_UPLOAD_AES_ENCRYPT_POST */
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_CONFIG_H_

View File

@@ -0,0 +1,87 @@
/**
* @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_host.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-12 <td>1.1 <td>fancyxu <td>change port to str format
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_HOST_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_HOST_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK APPID.
*
*/
#define QCLOUD_IOT_DEVICE_SDK_APPID "21010406"
#define QCLOUD_IOT_DEVICE_SDK_APPID_LEN (sizeof(QCLOUD_IOT_DEVICE_SDK_APPID) - 1)
/**
* @brief MQTT server domain.
*
*/
#define QCLOUD_IOT_MQTT_DIRECT_DOMAIN "iotcloud.tencentdevices.com"
#define MQTT_SERVER_PORT_TLS "8883"
#define MQTT_SERVER_PORT_NO_TLS "1883"
/**
* @brief Server domain for dynamic registering device.
*
*/
#define DYN_REG_SERVER_URL "ap-guangzhou.gateway.tencentdevices.com"
#define DYN_REG_URI_PATH "/device/register"
#define DYN_REG_SERVER_PORT "80"
#define DYN_REG_SERVER_PORT_TLS "443"
/**
* @brief URL for doing log upload.
*
*/
#define LOG_UPLOAD_SERVER_URL "ap-guangzhou.gateway.tencentdevices.com"
#define LOG_UPLOAD_URI_PATH "/device/reportlog"
#define LOG_UPLOAD_SERVER_PORT "80"
/**
* @brief (old)URL for doing log upload.
* Compatible with old versions, new users are recommended to use up
*
*/
#define LOG_UPLOAD_OLD_SERVER_URL "http://devicelog.iot.cloud.tencent.com/cgi-bin/report-log"
#define LOG_UPLOAD_OLD_SERVER_PORT "80"
/**
* @brief Max size of a host name.
*
*/
#define HOST_STR_LENGTH 64
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_HOST_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_variables.h
* @brief variables can be set depend on user resource.
* @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
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_VARIABLES_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_VARIABLES_H_
#ifdef __cplusplus
extern "C" {
#endif
// Variables are dependant on user situation (network status/device memory/application context). Adjust the default
// value to meet your requirement
/**
* @brief default MQTT timeout value when connect/pub/sub (unit: ms)
*
*/
#define QCLOUD_IOT_MQTT_COMMAND_TIMEOUT (5 * 1000)
/**
* @brief default MQTT timeout value when wait server ack
*
*/
#define QCLOUD_IOT_MQTT_WAIT_ACK_TIMEOUT (5 * 1000)
/**
* @brief default MQTT keep alive interval (unit: s)
*
*/
#define QCLOUD_IOT_MQTT_KEEP_ALIVE_INTERNAL (240)
/**
* @brief default MQTT Tx buffer size, MAX: 16*1024
*
*/
#define QCLOUD_IOT_MQTT_TX_BUF_LEN (4096)
/**
* @brief default MQTT Rx buffer size, MAX: 16*1024
*
*/
#define QCLOUD_IOT_MQTT_RX_BUF_LEN (4096)
/**
* @brief default MQTT timeout value when yield
*
*/
#define QCLOUD_IOT_MQTT_YIELD_TIMEOUT (500)
/**
* @brief MAX MQTT reconnect interval (unit: ms)
*
*/
#define MAX_RECONNECT_WAIT_INTERVAL (60 * 1000)
/**
* @brief MAX valid time when connect to MQTT server. 0: always valid.
* Use this only if the device has accurate UTC time. Otherwise, set to 0.
*
*/
#define MAX_ACCESS_EXPIRE_TIMEOUT (0)
// Log upload related params, which will affect the size of device memory/disk consumption Log upload related params,
// which will affect the size of device memory/disk consumption
/**
* @brief size of buffer for log upload
*
*/
#define LOG_UPLOAD_BUFFER_SIZE 5000
/**
* @brief Max size of one http log upload. Should not larger than 5000
*
*/
#define MAX_HTTP_LOG_POST_SIZE 5000
/**
* @brief MAX size for saving log into NVS (files/FLASH) after upload fail
*
*/
#define MAX_LOG_SAVE_SIZE (3 * LOG_UPLOAD_BUFFER_SIZE)
/**
* @brief interval of log upload (unit: ms) Decrease this value if LOG_UPLOAD_BUFFER_SIZE is small
*
*/
#define LOG_UPLOAD_INTERVAL_MS 1800000
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_VARIABLES_H_

View File

@@ -0,0 +1,70 @@
/**
* @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_common.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-08-23
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-08-23 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_COMMON_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_COMMON_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK version info
*
*/
#define QCLOUD_IOT_DEVICE_SDK_VERSION "4.0.0"
// common header file
#include "qcloud_iot_debug.h"
#include "qcloud_iot_device.h"
#include "qcloud_iot_error.h"
#include "qcloud_iot_params_check.h"
#include "qcloud_iot_platform.h"
#include "qcloud_iot_timer.h"
// config header file
#include "qcloud_iot_config.h"
#include "qcloud_iot_host.h"
#include "qcloud_iot_variables.h"
// service header file
#include "qcloud_iot_mqtt_client.h"
#include "qcloud_iot_system.h"
#include "qcloud_iot_ota.h"
#include "qcloud_iot_cos.h"
#include "qcloud_iot_http_client.h"
#include "qcloud_iot_log_upload.h"
#include "qcloud_iot_http_signed.h"
#include "qcloud_iot_dynreg.h"
#include "qcloud_iot_gateway.h"
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_COMMON_H_

View File

@@ -0,0 +1,51 @@
/**
* @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_explorer.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-08-23
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-08-23 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_EXPLORER_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_EXPLORER_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK version info
*
*/
#define QCLOUD_IOT_DEVICE_EXPLORER_SDK_VERSION "4.0.0"
// service header file
#include "qcloud_iot_data_template.h"
#include "qcloud_iot_file_manage.h"
#include "qcloud_iot_gateway_scene.h"
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_EXPLORER_H_

View File

@@ -0,0 +1,50 @@
/**
* @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_hub.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-18 <td>1.1 <td>fancyxu <td>support broadcast
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_HUB_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_HUB_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK version info
*
*/
#define QCLOUD_IOT_DEVICE_HUB_SDK_VERSION "4.0.0"
// service header file
#include "qcloud_iot_broadcast.h"
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_HUB_H_

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,151 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2022 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_gateway.h
* @brief
* @author willssong (willssong@tencent.com)
* @version 1.0
* @date 2022-01-23
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2022-01-23 <td>1.0 <td>willssong <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_GATEWAY_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_GATEWAY_H_
#include "qcloud_iot_common.h"
/**
* @brief Gateway reply result code.
* @ref https://cloud.tencent.com/document/product/1081/47442#.E9.94.99.E8.AF.AF.E7.A0.81
*
*/
typedef enum {
IOT_GATEWAY_RET_SUCCESS = 0,
IOT_GATEWAY_ERR_UNBIND = -1,
IOT_GATEWAY_ERR_FAIL = -2,
IOT_GATEWAY_ERR_PARAM = 801,
IOT_GATEWAY_ERR_SUBDEV_INVALID = 802,
IOT_GATEWAY_ERR_SIGN_FAIL = 803,
IOT_GATEWAY_ERR_SIGN_METHOD_UNSUPPORTED = 804,
IOT_GATEWAY_ERR_SIGN_EXPIRED = 805,
IOT_GATEWAY_ERR_SUBDEV_BIND_ALREADY = 806,
IOT_GATEWAY_ERR_SUBDEV_TYPE_NORMAL = 807,
IOT_GATEWAY_ERR_OPERATION_UNSUPPORTED = 808,
IOT_GATEWAY_ERR_BIND_REPEAT = 809,
IOT_GATEWAY_ERR_SUBDEV_UNSUPPORTED = 810
} IotGatewayResult;
/**
* @brief Callback of gateway.
*
*/
typedef struct {
void (*bind_unbind_reply_callback)(UtilsJsonValue sub_devices, bool is_bind, void *usr_data);
void (*unbind_all_callback)(void *usr_data);
void (*online_offline_reply_callback)(UtilsJsonValue sub_devices, bool is_online, void *usr_data);
void (*search_device_callback)(bool is_on, void *usr_data);
void (*describe_subdevices_reply_callback)(UtilsJsonValue sub_devices, void *usr_data);
void (*change_subdevices_status_callback)(UtilsJsonValue sub_devices, bool is_bind, void *usr_data);
} IotGatewayMessageCallback;
/**
* @brief Subscribe gateway topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IotGatewayMessageCallback
* @param[in] usr_data usr data using in callback
* @return @see IotReturnCode
*/
int IOT_Gateway_Init(void *client, IotGatewayMessageCallback callback, void *usr_data);
/**
* @brief Unsubscribe gateway topic.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_Gateway_Deinit(void *client);
/**
* @brief Get gateway init usr data.
*
* @param [in,out] client pointer to mqtt client
* @return usr data or NULL
*/
void *IOT_Gateway_GetUsrData(void *client);
/**
* @brief Publish subdevice online/offline message. @ref https://cloud.tencent.com/document/product/1081/47442
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer to hold publish message
* @param[in] buf_len buffer length
* @param[in] sub_dev_list subdevice list
* @param[in] num num of subdevice, @note only one subdevice is supported now.
* @param[in] is_online 1: online; 0: offline
* @return @see packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_Gateway_SubOnOffLine(void *client, char *buf, int buf_len, const DeviceInfo *sub_dev_list[], int num,
bool is_online);
/**
* @brief Publish subdevice bind/unbind message. @ref https://cloud.tencent.com/document/product/1081/47441
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer to hold publish message
* @param[in] buf_len buffer length
* @param[in] sub_dev_list subdevice list
* @param[in] num num of subdevice, @note only one subdevice is supported now.
* @param[in] is_bind 1: bind; 0: unbind
* @return @see packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_Gateway_BindUnbind(void *client, char *buf, int buf_len, const DeviceInfo *sub_dev_list[], int num,
bool is_bind);
/**
* @brief Publish subdevice describe message.
* @ref https://cloud.tencent.com/document/product/1081/47441#.E6.9F.A5.E8.AF.A2.E6.8B.93.E6.89.91.E5.85.B3.E7.B3.BB
*
* @param[in,out] client pointer to mqtt client
* @return @see packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_Gateway_Describe(void *client);
/**
* @brief Publish search device reply message.
* @ref
* https://cloud.tencent.com/document/product/1081/47441#.E9.80.9A.E7.9F.A5.E7.BD.91.E5.85.B3.E5.BC.80.E5.90.AF.E6.90.9C.E7.B4.A2.E7.8A.B6.E6.80.81
*
* @param[in,out] client pointer to mqtt client
* @param[in] is_on 1: on; 0: off
* @param[in] result 0: success; 1: fail
* @return @see packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_Gateway_SearchDeviceReply(void *client, bool is_on, int result);
/**
* @brief Publish unbind all reply message.
*
* @param[in,out] client pointer to mqtt client
* @param[in] result 0: success; 1: fail
* @return @see packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_Gateway_UnbindAllReply(void *client, int result);
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_GATEWAY_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_SignedRequest(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,128 @@
/**
* @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"
/**
* @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 void *buf, size_t write_len, size_t offset);
// callback for reading logs from NVS(files/FLASH) when upload ready
typedef size_t (*LogReadFunc)(const char *filename, void *buf, size_t read_len, size_t offset);
// 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;
/**
* @brief Default params.
*
*/
#define DEFAULT_LOG_UPLOAD_INIT_PARAMS \
{ \
NULL, NULL, NULL, NULL, LOG_UPLOAD_BUFFER_SIZE, NULL, NULL, NULL, NULL, NULL \
}
/**
* @brief Init log upload previously.
*
* @param[in] init_params @see LogUploadInitParams
* @return @see IotReturnCode
*/
int IOT_Log_Upload_InitPre(const 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);
/**
* @brief Append need report log to log upload buffer.
*
* @param[in] log_level @see LogLevel
* @param[in] log_content data of need to report
*/
void IOT_Log_Upload_AppendToUploadBuffer(LogLevel log_level, const char *log_content);
/**
* @brief Do log upload.
*
* @param[in] force_upload force upload when error
* @return @see IotReturnCode
*/
int IOT_Log_Upload(bool force_upload);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_LOG_UPLOAD_H_

View File

@@ -0,0 +1,339 @@
/**
* @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 */
} 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 const 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; /**< MQTT keep alive time interval in second */
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, QCLOUD_IOT_MQTT_COMMAND_TIMEOUT, QCLOUD_IOT_MQTT_KEEP_ALIVE_INTERNAL, 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,154 @@
/**
* @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"
#ifdef AT_MODULE_ENABLE
/**
* @brief Init ota && report mcu & at version.
*
* @param[in] version mcu version.
* @return 0 for success
*/
int IOT_OTA_Init(const char *version);
/**
* @brief Deinit ota.
*
* @return @see IotReturnCode
*/
void IOT_OTA_Deinit(void);
/**
* @brief Read fw info from at module.
*
* @param[out] version mcu fw version
* @param[out] fw_size mcu fw size
* @param[out] md5 mcu fw md5
* @param[in] timeout_ms timeout
* @return 0 for success
*/
int IOT_OTA_ReadFwInfo(char **version, uint32_t *fw_size, char **md5, uint32_t timeout_ms);
/**
* @brief Read fw data from at module.
*
* @param[out] fw_data fw data
* @param[out] fw_data_len fw data length
* @param[in] timeout_ms timeout
* @return 0 for success
*/
int IOT_OTA_ReadFWData(uint8_t *fw_data, uint32_t *fw_data_len, uint32_t timeout_ms);
#else
/**
* @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);
#endif
#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_

View File

@@ -0,0 +1,214 @@
/**
* @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_data_template.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-08-23
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-08-23 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_DATA_TEMPLATE_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_DATA_TEMPLATE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Callback of property.
*
*/
typedef struct {
void (*method_control_callback)(UtilsJsonValue client_token, UtilsJsonValue params, void *usr_data);
void (*method_report_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
void (*method_get_status_reply_callback)(UtilsJsonValue client_token, int code, UtilsJsonValue reported,
UtilsJsonValue control, void *usr_data);
void (*method_report_info_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
void (*method_clear_control_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
} PropertyMessageCallback;
/**
* @brief Callback of event.
*
*/
typedef struct {
void (*method_event_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
} EventMessageCallback;
/**
* @brief Callback of action.
*
*/
typedef struct {
void (*method_action_callback)(UtilsJsonValue client_token, UtilsJsonValue action_id, UtilsJsonValue params,
void *usr_data);
} ActionMessageCallback;
/**
* @brief Callback of data template(including property/event/action).
*
*/
typedef struct {
PropertyMessageCallback property_callback;
EventMessageCallback event_callback;
ActionMessageCallback action_callback;
} IotDataTemplateCallback;
#define DEFAULT_DATA_TEMPLATE_CALLBACK \
{ \
{NULL, NULL, NULL, NULL, NULL}, {NULL}, {NULL}, \
}
/**
* @brief Type of event.
*
*/
typedef enum {
IOT_DATA_TEMPLATE_EVENT_TYPE_INFO = 0,
IOT_DATA_TEMPLATE_EVENT_TYPE_ALERT,
IOT_DATA_TEMPLATE_EVENT_TYPE_FAULT,
} IotDataTemplateEventType;
/**
* @brief Post data.
*
*/
typedef struct {
const char * event_id; /**< event id defined in data template */
IotDataTemplateEventType type; /**< event type defined in data template */
const char * params; /**< property json defined in data template */
} IotDataTemplateEventData;
/**
* @brief Action reply.
*
*/
typedef struct {
UtilsJsonValue client_token;
int code;
const char * response; /**< property json defined in data template */
} IotDataTemplateActionReply;
/**
* @brief Check and subscribe data template topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IotDataTemplateCallback
* @param[in] usr_data usr data used in callback
* @return 0 for success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_Init(void *client, IotDataTemplateCallback callback, void *usr_data);
/**
* @brief Unsubscribe data template topic.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_DataTemplate_Deinit(void *client);
/**
* @brief Report property.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] params params constructed with property
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyReport(void *client, char *buf, int buf_len, const char *params);
/**
* @brief Get control message offline.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyGetStatus(void *client, char *buf, int buf_len);
/**
* @brief Report device info.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] params params constructed with device info
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyReportInfo(void *client, char *buf, int buf_len, const char *params);
/**
* @brief Clear control message offline.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyClearControl(void *client, char *buf, int buf_len);
/**
* @brief Reply control message.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] code 0 for success
* @param[in] client_token client token of control message
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyControlReply(void *client, char *buf, int buf_len, int code, UtilsJsonValue client_token);
/**
* @brief Post event.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] data @see IotDataTemplateEventData
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_EventPost(void *client, char *buf, int buf_len, IotDataTemplateEventData data);
/**
* @brief Reply action message.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] reply @see IotDataTemplateActionReply
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_ActionReply(void *client, char *buf, int buf_len, IotDataTemplateActionReply reply);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_DATA_TEMPLATE_H_

View File

@@ -0,0 +1,179 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2022 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_file_manage.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2022-01-11
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2022-01-11 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_FILE_MANAGE_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_FILE_MANAGE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Define of max size using in file manage.
*
*/
#define MAX_SIZE_OF_FILE_MANAGE_FILE_NAME 64
#define MAX_SIZE_OF_FILE_MANAGE_FILE_TYPE 10
#define MAX_SIZE_OF_FILE_MANAGE_FILE_VERSION 64
/**
* @brief FileManage report type.
*
*/
typedef enum {
// file update
IOT_FILE_MANAGE_REPORT_TYPE_DOWNLOADING = 0,
IOT_FILE_MANAGE_REPORT_TYPE_UPGRADE_BEGIN,
IOT_FILE_MANAGE_REPORT_TYPE_UPGRADE_SUCCESS,
IOT_FILE_MANAGE_REPORT_TYPE_DOWNLOAD_TIMEOUT,
IOT_FILE_MANAGE_REPORT_TYPE_FILE_NOT_EXIST,
IOT_FILE_MANAGE_REPORT_TYPE_AUTH_FAIL,
IOT_FILE_MANAGE_REPORT_TYPE_MD5_NOT_MATCH,
IOT_FILE_MANAGE_REPORT_TYPE_UPGRADE_FAIL,
IOT_FILE_MANAGE_REPORT_TYPE_SPACE_NOT_ENOUGH,
// file delete
IOT_FILE_MANAGE_REPORT_TYPE_DEL_SUCCESS,
IOT_FILE_MANAGE_REPORT_TYPE_DEL_FAIL,
// file post
IOT_FILE_MANAGE_REPORT_TYPE_POST_SUCCESS,
IOT_FILE_MANAGE_REPORT_TYPE_POST_FAIL,
} IotFileManageReportType;
/**
* @brief FileManage file type. @see sg_file_manage_file_type_str
*
*/
typedef enum {
IOT_FILE_MANAGE_FILE_TYPE_UNKOWN = -1,
IOT_FILE_MANAGE_FILE_TYPE_FILE = 0,
IOT_FILE_MANAGE_FILE_TYPE_AUDIO,
IOT_FILE_MANAGE_FILE_TYPE_VOICE,
IOT_FILE_MANAGE_FILE_TYPE_VIDEO,
} IotFileManageFileType;
/**
* @brief File info.
*
*/
typedef struct {
char file_name[MAX_SIZE_OF_FILE_MANAGE_FILE_NAME];
char file_version[MAX_SIZE_OF_FILE_MANAGE_FILE_VERSION];
IotFileManageFileType file_type;
} IotFileManageFileInfo;
/**
* @brief Callback of FileManage.
*
*/
typedef struct {
void (*update_file_callback)(UtilsJsonValue file_name, UtilsJsonValue file_type, UtilsJsonValue version,
UtilsJsonValue url, UtilsJsonValue md5sum, uint32_t file_size, void *usr_data);
void (*del_file_callback)(UtilsJsonValue file_name, UtilsJsonValue file_type, UtilsJsonValue version,
void *usr_data);
void (*report_file_version_reponse_callback)(UtilsJsonValue file_list, int result_code, void *usr_data);
void (*request_file_url_response_callback)(UtilsJsonValue url, UtilsJsonValue file_token, int result_code,
void *usr_data);
} IotFileManageCallback;
/**
* @brief File manage init, register handler to server list.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IotFileManageCallback
* @param[in] usr_data usr data used in callback
* @return 0 for success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_Init(void *client, IotFileManageCallback callback, void *usr_data);
/**
* @brief File manage deinit, unregister handler from server list.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_FileManage_Deinit(void *client);
/**
* @brief Report file manage message.
*
* @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 IotFileManageReportType
* @param[in] progress progress using in IOT_FILE_MANAGE_REPORT_TYPE_DOWNLOADING
* @param[in] file_name_or_token token using in post event;file name using in other event
* @param[in] version file version
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_Report(void *client, char *buf, int buf_len, IotFileManageReportType report_type, int progress,
const char *file_name_or_token, const char *version);
/**
* @brief Report file list to server mqtt topic.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] file_list file list of @see IotFileManageFileInfo; file name which is "\0" means invalid.
* @param[in] max_num max num of file list.
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_ReportFileList(void *client, char *buf, int buf_len, const IotFileManageFileInfo file_list[],
int max_num);
/**
* @brief Request url to upload.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] file_info file to upload, @see IotFileManageFileInfo
* @param[in] request_id user defined, to keep unique.
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_PostRequest(void *client, char *buf, int buf_len, const IotFileManageFileInfo *file_info,
int request_id);
/**
* @brief Get file type according to string. @see sg_file_manage_file_type_str.
*
* @param[in] file_type file type string
* @param[in] len string length
* @return @see IotFileManageFileType
*/
IotFileManageFileType IOT_FileManage_GetFileType(const char *file_type, int len);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_FILE_MANAGE_H_

View File

@@ -0,0 +1,113 @@
/**
* @file qcloud_iot_gateway_scene.h
* @author {hubert} ({hubertxxu@tencent.com})
* @brief
* @version 1.0
* @date 2022-06-15
*
* @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-06-15 1.0 hubertxxu first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_GATEWAY_SCENE_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_GATEWAY_SCENE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
#define MAX_LENGTH_INNER_SCENE_ID (64)
#define MAX_LENGTH_INNER_SCENE_NAME (64)
#define MAX_LENGTH_INNER_SCENE_LIST (20)
/**
* @brief callback of gateway scene
*
*/
typedef struct {
int (*gateway_scene_handles_callback)(UtilsJsonValue scene_id, UtilsJsonValue scene_name,
UtilsJsonValue scene_update_time, UtilsJsonValue scene_handles,
void *usr_data);
int (*gateway_run_scene_callback)(UtilsJsonValue scene_id, void *usr_data);
int (*gateway_delete_scene_callback)(UtilsJsonValue scene_id, void *usr_data);
int (*gateway_reload_scene_reply_callback)(int result_code, UtilsJsonValue status, UtilsJsonValue scene_result,
void *usr_data);
} IoTGatewaySceneCallback;
/**
* @brief gateway scene inner list
*
*/
typedef struct {
char inner_scene_id[MAX_LENGTH_INNER_SCENE_ID];
char inner_scene_name[MAX_LENGTH_INNER_SCENE_NAME];
} IoTGatewaySceneInnerList;
/**
* @brief gateway scene init, register handler to server list.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IoTGatewaySceneCallback
* @param[in] usr_data usr data used in callback
* @return 0 for success, or err code (<0) @see IotReturnCode
*/
int IOT_GatewayScene_Init(void *client, IoTGatewaySceneCallback callback, void *usr_data);
/**
* @brief Gateway scene deinit, unregister handler from server list.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_GatewayScene_Deinit(void *client);
/**
* @brief reload gateway scene from cloud.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_GatewayScene_Reload(void *client, char *buf, int buf_len);
/**
* @brief report gateway local scene
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param list local scene list
* @param list_count local scene list count
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_GatewayScene_ReportInnerList(void *client, char *buf, int buf_len, IoTGatewaySceneInnerList *list,
int list_count);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_GATEWAY_SCENE_H_

View File

@@ -0,0 +1,70 @@
/**
* @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_broadcast.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-07-18
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-07-18 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_HUB_QCLOUD_IOT_BROADCAST_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_HUB_QCLOUD_IOT_BROADCAST_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Callback when broadcast message arrived.
*
*/
typedef void (*OnBroadcastArrivedCallback)(void *client, const char *msg, int msg_len, void *usr_data);
/**
* @brief Subscribe broadcast topic with callback.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback callback to handle message
* @param[in] usr_data usr data using in callback
* @return @see IotReturnCode
*/
int IOT_Broadcast_Init(void *client, OnBroadcastArrivedCallback callback, void *usr_data);
/**
* @brief Unsubscribe broadcast topic.
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Broadcast_Deinit(void *client);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_HUB_QCLOUD_IOT_BROADCAST_H_