esp_smartconfig.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __ESP_SMARTCONFIG_H__
  7. #define __ESP_SMARTCONFIG_H__
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include "esp_err.h"
  11. #include "esp_event_base.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef enum {
  16. SC_TYPE_ESPTOUCH = 0, /**< protocol: ESPTouch */
  17. SC_TYPE_AIRKISS, /**< protocol: AirKiss */
  18. SC_TYPE_ESPTOUCH_AIRKISS, /**< protocol: ESPTouch and AirKiss */
  19. SC_TYPE_ESPTOUCH_V2, /**< protocol: ESPTouch v2*/
  20. } smartconfig_type_t;
  21. /** Smartconfig event declarations */
  22. typedef enum {
  23. SC_EVENT_SCAN_DONE, /*!< Station smartconfig has finished to scan for APs */
  24. SC_EVENT_FOUND_CHANNEL, /*!< Station smartconfig has found the channel of the target AP */
  25. SC_EVENT_GOT_SSID_PSWD, /*!< Station smartconfig got the SSID and password */
  26. SC_EVENT_SEND_ACK_DONE, /*!< Station smartconfig has sent ACK to cellphone */
  27. } smartconfig_event_t;
  28. /** @brief smartconfig event base declaration */
  29. ESP_EVENT_DECLARE_BASE(SC_EVENT);
  30. /** Argument structure for SC_EVENT_GOT_SSID_PSWD event */
  31. typedef struct {
  32. uint8_t ssid[32]; /**< SSID of the AP. Null terminated string. */
  33. uint8_t password[64]; /**< Password of the AP. Null terminated string. */
  34. bool bssid_set; /**< whether set MAC address of target AP or not. */
  35. uint8_t bssid[6]; /**< MAC address of target AP. */
  36. smartconfig_type_t type; /**< Type of smartconfig(ESPTouch or AirKiss). */
  37. uint8_t token; /**< Token from cellphone which is used to send ACK to cellphone. */
  38. uint8_t cellphone_ip[4]; /**< IP address of cellphone. */
  39. } smartconfig_event_got_ssid_pswd_t;
  40. /** Configure structure for esp_smartconfig_start */
  41. typedef struct {
  42. bool enable_log; /**< Enable smartconfig logs. */
  43. bool esp_touch_v2_enable_crypt; /**< Enable ESPTouch v2 crypt. */
  44. char *esp_touch_v2_key; /**< ESPTouch v2 crypt key, len should be 16. */
  45. } smartconfig_start_config_t;
  46. #define SMARTCONFIG_START_CONFIG_DEFAULT() { \
  47. .enable_log = false, \
  48. .esp_touch_v2_enable_crypt = false,\
  49. .esp_touch_v2_key = NULL \
  50. };
  51. /**
  52. * @brief Get the version of SmartConfig.
  53. *
  54. * @return
  55. * - SmartConfig version const char.
  56. */
  57. const char *esp_smartconfig_get_version(void);
  58. /**
  59. * @brief Start SmartConfig, config ESP device to connect AP. You need to broadcast information by phone APP.
  60. * Device sniffer special packets from the air that containing SSID and password of target AP.
  61. *
  62. * @attention 1. This API can be called in station or softAP-station mode.
  63. * @attention 2. Can not call esp_smartconfig_start twice before it finish, please call
  64. * esp_smartconfig_stop first.
  65. *
  66. * @param config pointer to smartconfig start configure structure
  67. *
  68. * @return
  69. * - ESP_OK: succeed
  70. * - others: fail
  71. */
  72. esp_err_t esp_smartconfig_start(const smartconfig_start_config_t *config);
  73. /**
  74. * @brief Stop SmartConfig, free the buffer taken by esp_smartconfig_start.
  75. *
  76. * @attention Whether connect to AP succeed or not, this API should be called to free
  77. * memory taken by smartconfig_start.
  78. *
  79. * @return
  80. * - ESP_OK: succeed
  81. * - others: fail
  82. */
  83. esp_err_t esp_smartconfig_stop(void);
  84. /**
  85. * @brief Set timeout of SmartConfig process.
  86. *
  87. * @attention Timing starts from SC_STATUS_FIND_CHANNEL status. SmartConfig will restart if timeout.
  88. *
  89. * @param time_s range 15s~255s, offset:45s.
  90. *
  91. * @return
  92. * - ESP_OK: succeed
  93. * - others: fail
  94. */
  95. esp_err_t esp_esptouch_set_timeout(uint8_t time_s);
  96. /**
  97. * @brief Set protocol type of SmartConfig.
  98. *
  99. * @attention If users need to set the SmartConfig type, please set it before calling
  100. * esp_smartconfig_start.
  101. *
  102. * @param type Choose from the smartconfig_type_t.
  103. *
  104. * @return
  105. * - ESP_OK: succeed
  106. * - others: fail
  107. */
  108. esp_err_t esp_smartconfig_set_type(smartconfig_type_t type);
  109. /**
  110. * @brief Set mode of SmartConfig. default normal mode.
  111. *
  112. * @attention 1. Please call it before API esp_smartconfig_start.
  113. * @attention 2. Fast mode have corresponding APP(phone).
  114. * @attention 3. Two mode is compatible.
  115. *
  116. * @param enable false-disable(default); true-enable;
  117. *
  118. * @return
  119. * - ESP_OK: succeed
  120. * - others: fail
  121. */
  122. esp_err_t esp_smartconfig_fast_mode(bool enable);
  123. /**
  124. * @brief Get reserved data of ESPTouch v2.
  125. *
  126. * @param rvd_data reserved data
  127. * @param len length of reserved data
  128. *
  129. * @return
  130. * - ESP_OK: succeed
  131. * - others: fail
  132. */
  133. esp_err_t esp_smartconfig_get_rvd_data(uint8_t *rvd_data, uint8_t len);
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif