Documentation

Documentation

Includes

tuya_iot_config.h

#include "tuya_iot_config.h"
#include "tuya_iot_config.h"

tuya_cloud_types.h

#include "tuya_cloud_types.h"
#include "tuya_cloud_types.h"

tuya_hal_network.h

#include "tuya_hal_network.h"
#include "tuya_hal_network.h"

Macros

Marco __TUYA_BASE_UNI_DNS_CACHE_H__

#define __TUYA_BASE_UNI_DNS_CACHE_H__


      

Marco MAX_DOMAIN_NAME_LEN

#define MAX_DOMAIN_NAME_LEN    128
/**
 * @brief max length of domain name
 * 
 */

Marco HTTP_DNS_SERVER_DOMAIN

#define HTTP_DNS_SERVER_DOMAIN   "h3.iot-dns.com"
// TLS_MODE==TLS_TUYA_PSK_ONLY or TLS_MODE==TLS_TUYA_ECC_PSK

Marco HTTP_DNS_SERVER_DOMAIN_WE

#define HTTP_DNS_SERVER_DOMAIN_WE "h3-we.iot-dns.com"


      

Marco HTTP_DNS_SERVER_DOMAIN

#define HTTP_DNS_SERVER_DOMAIN   "h4.iot-dns.com"
// TLS_MODE==TLS_TUYA_ECC_CLIENT_AUTH

Marco HTTP_DNS_SERVER_DOMAIN_WE

#define HTTP_DNS_SERVER_DOMAIN_WE "h4-we.iot-dns.com"


      

Marco HTTP_DNS_SERVER_DOMAIN

#define HTTP_DNS_SERVER_DOMAIN   "h2.iot-dns.com"
// TLS_MODE==TLS_TUYA_PSK_ONLY or TLS_MODE==TLS_TUYA_ECC_ONLY_NOSTRIP

Marco HTTP_DNS_SERVER_DOMAIN_WE

#define HTTP_DNS_SERVER_DOMAIN_WE "h2-we.iot-dns.com"

      

Functions

Func unw_gethostbyname

OPERATE_RET unw_gethostbyname(CONST CHAR_T *domain, UNW_IP_ADDR_T *addr);
/**
 * @brief get the domain ip address info by the domain name
 * 
 * @param[in] domain the domain name 
 * @param[out] addr the ip address of the domain
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unw_connect_to_domain

OPERATE_RET unw_connect_to_domain(INT_T *sockfd, CHAR_T *hostname, UINT16_T port, UINT_T retry_cnt, UINT_T timeout);
/**
 * @brief connect to a domain with specific tcp port
 * 
 * @param[out] sockfd the socket fd
 * @param[in] hostname the domian name
 * @param[in] port the tcp port
 * @param[in] retry_cnt retry count if tcp connect failed
 * @param[in] timeout timeout in ms
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unw_init_dns_cache

OPERATE_RET unw_init_dns_cache(VOID);
/**
 * @brief init the dns module
 * 
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unw_clear_all_dns_cache

OPERATE_RET unw_clear_all_dns_cache(VOID);
/**
 * @brief clean all dynamic dns cache
 * 
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unw_clear_dns_cache

OPERATE_RET unw_clear_dns_cache(CONST CHAR_T *domain);
/**
 * @brief clear the specific domain dns cache
 * 
 * @param[in] domain the domian which need to clear
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unw_add_dns_cache

OPERATE_RET unw_add_dns_cache(CONST CHAR_T *domain, CONST UNW_IP_ADDR_T ip);
/**
 * @brief add dns information to dynamic dns cache
 * 
 * @param[in] domain the domian name
 * @param[in] ip the ip address of the domain name
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unm_set_dns_region

OPERATE_RET unm_set_dns_region(REGION_E region);
/**
 * @brief set the dns current region
 * 
 * @param[in] region the new current region
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unm_set_dns_cache_priority

OPERATE_RET unm_set_dns_cache_priority(TY_DNS_PRIO_T dns_prio);
/**
 * @brief set the dns priority
 * 
 * @param[in] dns_prio the new dns priority
 * @return OPRT_OK: success, others: fail, please refer to tuya_error_code.h  
 */

Func unm_get_dns_cache_priority

TY_DNS_PRIO_T unm_get_dns_cache_priority(VOID);
/**
 * @brief get the dns current priority
 * 
 * @return REGION_E the current priority
 */

Func unm_lower_dns_cache_priority

VOID unm_lower_dns_cache_priority(VOID);
/**
 * @brief decrease the dns current priority
 * 
 * @note if the priority is DNS_PRIO_SYSTEM, lower dns priority will return to DNS_PRIO_REGION
 */

Vars

Consts

Types

Typedefs

Typedef REGION_E

typedef UINT_T REGION_E;
#define E_REGION_DYNAMIC 0     // no fixed region
#define E_REGION_CN 1          // china region
#define E_REGION_EU 2          // european region
#define E_REGION_US 3          // american region
#define E_REGION_UE 4          // west american region
#define E_REGION_IN 5          // indian region
#define E_REGION_WE 6          // west european region
#define E_REGION_MAX 7         // region max

/**
 * @brief DNS region
 * 
 */

Typedef TY_DNS_PRIO_T

typedef UINT_T TY_DNS_PRIO_T;
#define DNS_PRIO_REGION 0  // default priority, use the dns server of current region
#define DNS_PRIO_RANDOM 1  // select a random dns server of the regions except current region
#define DNS_PRIO_SYSTEM 2  // use the system dns service of the router

/**
 * @brief DNS priority
 * 
 */

Typedef TY_DNS_INFO_S;

typedef struct
{
   REGION_E       region; // the region of the DNS entry
   CHAR_T         *domain;// the domain of the DNS entry
   UNW_IP_ADDR_T  ip;    // the ip address of the DNS entry
}TY_DNS_INFO_S;
/**
 * @brief DNS entry info
 * 
 */