app_prov.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Console based Provisioning Example
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #pragma once
  8. #include <esp_event_loop.h>
  9. #include <protocomm_security.h>
  10. #include <wifi_provisioning/wifi_config.h>
  11. /**
  12. * @brief Get state of WiFi Station during provisioning
  13. *
  14. * @note WiFi is initially configured as AP, when
  15. * provisioning starts. After provisioning data
  16. * is provided by user, the WiFi is reconfigured
  17. * to run as both AP and Station.
  18. *
  19. * @param[out] state Pointer to wifi_prov_sta_state_t variable to be filled
  20. *
  21. * @return
  22. * - ESP_OK : Successfully retrieved wifi state
  23. * - ESP_FAIL : Provisioning app not running
  24. */
  25. esp_err_t app_prov_get_wifi_state(wifi_prov_sta_state_t* state);
  26. /**
  27. * @brief Get reason code in case of WiFi station
  28. * disconnection during provisioning
  29. *
  30. * @param[out] reason Pointer to wifi_prov_sta_fail_reason_t variable to be filled
  31. *
  32. * @return
  33. * - ESP_OK : Successfully retrieved wifi disconnect reason
  34. * - ESP_FAIL : Provisioning app not running
  35. */
  36. esp_err_t app_prov_get_wifi_disconnect_reason(wifi_prov_sta_fail_reason_t* reason);
  37. /**
  38. * @brief Event handler for provisioning app
  39. *
  40. * This is called from the main event handler and controls the
  41. * provisioning application, depeding on WiFi events
  42. *
  43. * @param[in] ctx Event context data
  44. * @param[in] event Event info
  45. *
  46. * @return
  47. * - ESP_OK : Event handled successfully
  48. * - ESP_FAIL : Failed to start server on event AP start
  49. */
  50. esp_err_t app_prov_event_handler(void *ctx, system_event_t *event);
  51. /**
  52. * @brief Checks if device is provisioned
  53. * *
  54. * @param[out] provisioned True if provisioned, else false
  55. *
  56. * @return
  57. * - ESP_OK : Retrieved provision state successfully
  58. * - ESP_FAIL : Failed to retrieve provision state
  59. */
  60. esp_err_t app_prov_is_provisioned(bool *provisioned);
  61. /**
  62. * @brief Runs WiFi as Station
  63. *
  64. * Configures the WiFi station mode to connect to the
  65. * SSID and password specified in config structure,
  66. * and starts WiFi to run as station
  67. *
  68. * @param[in] wifi_cfg Pointer to WiFi cofiguration structure
  69. *
  70. * @return
  71. * - ESP_OK : WiFi configured and started successfully
  72. * - ESP_FAIL : Failed to set configuration
  73. */
  74. esp_err_t app_prov_configure_sta(wifi_config_t *wifi_cfg);
  75. /**
  76. * @brief Start provisioning via Console
  77. *
  78. * @param[in] security Security mode
  79. * @param[in] pop Pointer to proof of possession (NULL if not present)
  80. *
  81. * @return
  82. * - ESP_OK : Provisioning started successfully
  83. * - ESP_FAIL : Failed to start
  84. */
  85. esp_err_t app_prov_start_console_provisioning(int security, const protocomm_security_pop_t *pop);