esp_smartconfig.h 4.7 KB

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