esp_smartconfig.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_SMARTCONFIG_H__
  14. #define __ESP_SMARTCONFIG_H__
  15. #include <stdint.h>
  16. #include <esp_types.h>
  17. #include "esp_err.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. typedef enum {
  22. SC_STATUS_WAIT = 0, /**< waiting, do not start connection in this phase */
  23. SC_STATUS_FIND_CHANNEL, /**< find target channel, start connection by APP in this phase */
  24. SC_STATUS_GETTING_SSID_PSWD, /**< getting SSID and password of target AP */
  25. SC_STATUS_LINK, /**< connecting to target AP */
  26. SC_STATUS_LINK_OVER, /**< got IP, connect to AP successfully */
  27. } smartconfig_status_t;
  28. typedef enum {
  29. SC_TYPE_ESPTOUCH = 0, /**< protocol: ESPTouch */
  30. SC_TYPE_AIRKISS, /**< protocol: AirKiss */
  31. SC_TYPE_ESPTOUCH_AIRKISS, /**< protocol: ESPTouch and AirKiss */
  32. } smartconfig_type_t;
  33. /**
  34. * @brief The callback of SmartConfig, executed when smart-config status changed.
  35. *
  36. * @param smartconfig_status_t status : status of SmartConfig:
  37. * - if status == SC_STATUS_GETTING_SSID_PSWD, parameter void *pdata is a pointer
  38. of smartconfig_type_t, means SmartConfig type: AirKiss or ESP-TOUCH.
  39. * - if status == SC_STATUS_LINK, parameter void *pdata is a pointer of struct station_config;
  40. * - if status == SC_STATUS_LINK_OVER, parameter void *pdata is a pointer of mobile
  41. * phone's IP address, 4 bytes. This is only available in ESPTOUCH, otherwise,
  42. * it is NULL.
  43. * - otherwise, parameter void *pdata is NULL.
  44. * @param void *pdata : data of SmartConfig
  45. *
  46. * @return null
  47. */
  48. typedef void (*sc_callback_t)(smartconfig_status_t status, void *pdata);
  49. /**
  50. * @brief Get the version of SmartConfig.
  51. *
  52. * @param null
  53. *
  54. * @return SmartConfig version
  55. */
  56. const char *esp_smartconfig_get_version(void);
  57. /**
  58. * @brief Start SmartConfig mode.
  59. *
  60. * Start SmartConfig mode, to connect ESP32 station to AP, by sniffing
  61. * for special packets from the air, containing SSID and password of desired AP.
  62. * You need to broadcast the SSID and password (e.g. from mobile device or computer)
  63. * with the SSID and password encoded.
  64. *
  65. * @attention 1. This API can only be called in station mode.
  66. * @attention 2. During SmartConfig, ESP32 station and soft-AP are disabled.
  67. * @attention 3. Can not call esp_smartconfig_start twice before it finish, please call
  68. * esp_smartconfig_stop first.
  69. * @attention 4. Don't call any other APIs during SmartConfig, please call esp_smartconfig_stop first.
  70. *
  71. * @param sc_callback_t cb : SmartConfig callback; executed when SmartConfig status changed;
  72. * @param uint8 log : 1, UART output logs; otherwise, UART only outputs the result.
  73. *
  74. * @return ESP_OK : succeed
  75. * @return others : fail
  76. */
  77. esp_err_t esp_smartconfig_start(sc_callback_t cb, ...);
  78. /**
  79. * @brief Stop SmartConfig, free the buffer taken by esp_smartconfig_start.
  80. *
  81. * @attention Whether connect to AP succeed or not, this API should be called to free
  82. * memory taken by smartconfig_start.
  83. *
  84. * @param null
  85. *
  86. * @return ESP_OK : succeed
  87. * @return others : fail
  88. */
  89. esp_err_t esp_smartconfig_stop(void);
  90. /**
  91. * @brief Set timeout of SmartConfig.
  92. *
  93. * @attention SmartConfig timeout start at SC_STATUS_FIND_CHANNEL, SmartConfig will
  94. * restart if timeout.
  95. *
  96. * @param uint8 time_s : range 15s~255s, offset:45s.
  97. *
  98. * @return ESP_OK : succeed
  99. * @return others : fail
  100. */
  101. esp_err_t esp_esptouch_set_timeout(uint8_t time_s);
  102. /**
  103. * @brief Set protocol type of SmartConfig.
  104. *
  105. * @attention If users need to set the SmartConfig type, please set it before calling
  106. * esp_smartconfig_start.
  107. *
  108. * @param smartconfig_type_t type : AirKiss, ESP-TOUCH or both.
  109. *
  110. * @return ESP_OK : succeed
  111. * @return others : fail
  112. */
  113. esp_err_t esp_smartconfig_set_type(smartconfig_type_t type);
  114. /**
  115. * @brief Set mode of SmartConfig. default normal mode.
  116. *
  117. * @attention If users need to set the SmartConfig mode, please set it before calling
  118. * esp_smartconfig_start. Different mode should match different APP(phone).
  119. *
  120. * @param bool enable : false-disable(default); true-enable;
  121. *
  122. * @return ESP_OK : succeed
  123. * @return others : fail
  124. */
  125. esp_err_t esp_smartconfig_fast_mode(bool enable);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif