esp_smartconfig.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef enum {
  23. SC_STATUS_WAIT = 0, /**< Waiting to start connect */
  24. SC_STATUS_FIND_CHANNEL, /**< Finding target channel */
  25. SC_STATUS_GETTING_SSID_PSWD, /**< Getting SSID and password of target AP */
  26. SC_STATUS_LINK, /**< Connecting to target AP */
  27. SC_STATUS_LINK_OVER, /**< Connected to AP successfully */
  28. } smartconfig_status_t;
  29. typedef enum {
  30. SC_TYPE_ESPTOUCH = 0, /**< protocol: ESPTouch */
  31. SC_TYPE_AIRKISS, /**< protocol: AirKiss */
  32. SC_TYPE_ESPTOUCH_AIRKISS, /**< protocol: ESPTouch and AirKiss */
  33. } smartconfig_type_t;
  34. /**
  35. * @brief The callback of SmartConfig, executed when smart-config status changed.
  36. *
  37. * @param status Status of SmartConfig:
  38. * - SC_STATUS_GETTING_SSID_PSWD : pdata is a pointer of smartconfig_type_t, means config type.
  39. * - SC_STATUS_LINK : pdata is a pointer of struct station_config.
  40. * - SC_STATUS_LINK_OVER : pdata is a pointer of phone's IP address(4 bytes) if pdata unequal NULL.
  41. * - otherwise : parameter void *pdata is NULL.
  42. * @param pdata According to the different status have different values.
  43. *
  44. */
  45. typedef void (*sc_callback_t)(smartconfig_status_t status, void *pdata);
  46. /**
  47. * @brief Get the version of SmartConfig.
  48. *
  49. * @return
  50. * - SmartConfig version const char.
  51. */
  52. const char *esp_smartconfig_get_version(void);
  53. /**
  54. * @brief Start SmartConfig, config ESP device to connect AP. You need to broadcast information by phone APP.
  55. * Device sniffer special packets from the air that containing SSID and password of target AP.
  56. *
  57. * @attention 1. This API can be called in station or softAP-station mode.
  58. * @attention 2. Can not call esp_smartconfig_start twice before it finish, please call
  59. * esp_smartconfig_stop first.
  60. *
  61. * @param cb SmartConfig callback function.
  62. * @param ... log 1: UART output logs; 0: UART only outputs the result.
  63. *
  64. * @return
  65. * - ESP_OK: succeed
  66. * - others: fail
  67. */
  68. esp_err_t esp_smartconfig_start(sc_callback_t cb, ...);
  69. /**
  70. * @brief Stop SmartConfig, free the buffer taken by esp_smartconfig_start.
  71. *
  72. * @attention Whether connect to AP succeed or not, this API should be called to free
  73. * memory taken by smartconfig_start.
  74. *
  75. * @return
  76. * - ESP_OK: succeed
  77. * - others: fail
  78. */
  79. esp_err_t esp_smartconfig_stop(void);
  80. /**
  81. * @brief Set timeout of SmartConfig process.
  82. *
  83. * @attention Timing starts from SC_STATUS_FIND_CHANNEL status. SmartConfig will restart if timeout.
  84. *
  85. * @param time_s range 15s~255s, offset:45s.
  86. *
  87. * @return
  88. * - ESP_OK: succeed
  89. * - others: fail
  90. */
  91. esp_err_t esp_esptouch_set_timeout(uint8_t time_s);
  92. /**
  93. * @brief Set protocol type of SmartConfig.
  94. *
  95. * @attention If users need to set the SmartConfig type, please set it before calling
  96. * esp_smartconfig_start.
  97. *
  98. * @param type Choose from the smartconfig_type_t.
  99. *
  100. * @return
  101. * - ESP_OK: succeed
  102. * - others: fail
  103. */
  104. esp_err_t esp_smartconfig_set_type(smartconfig_type_t type);
  105. /**
  106. * @brief Set mode of SmartConfig. default normal mode.
  107. *
  108. * @attention 1. Please call it before API esp_smartconfig_start.
  109. * @attention 2. Fast mode have corresponding APP(phone).
  110. * @attention 3. Two mode is compatible.
  111. *
  112. * @param enable false-disable(default); true-enable;
  113. *
  114. * @return
  115. * - ESP_OK: succeed
  116. * - others: fail
  117. */
  118. esp_err_t esp_smartconfig_fast_mode(bool enable);
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif