esp_smartconfig.h 5.3 KB

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