wifi_provisioning.rst 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Wi-Fi Provisioning
  2. ==================
  3. Overview
  4. --------
  5. This component provides protocomm endpoint handler - `wifi_prov_config_data_handler` - and related protobuf framework which can be used for Wi-Fi configuration in the context of device provisioning, though it may be used in non-provisioning cases as well.
  6. The configuration consists of three commands :
  7. * `get_status` - For querying the Wi-Fi connection status
  8. * `set_config` - For setting the Wi-Fi connection credentials
  9. * `apply_config` - For applying the credentials saved during `set_config` and (re)start the Wi-Fi station
  10. The way this is supposed to work is that the desired Wi-Fi configuration for the ESP32, which is to run as a station and thus connect to an AP with certain credentials, is to be sent during `set_config`. Then `apply_config` is supposed to start (or restart) the Wi-Fi in station mode with the previously set AP credentials. Afterwords, `get_config` command is used to probe the device continuously for Wi-Fi connection status, to ensure that the connection was indeed successful. If the connection failed, then appropriate status code along with disconnection reason, is to be conveyed through `get_config`.
  11. Application Example
  12. -------------------
  13. .. highlight:: c
  14. ::
  15. esp_err_t get_status_handler(wifi_prov_config_get_data_t *resp_data, wifi_prov_ctx_t **ctx)
  16. {
  17. /* Fill the wifi_prov_config_get_data_t structure
  18. * with Wi-Fi station connection status information. */
  19. return ESP_OK;
  20. }
  21. esp_err_t set_config_handler(const wifi_prov_config_set_data_t *req_data, wifi_prov_ctx_t **ctx)
  22. {
  23. /* Copy contents of req_data->ssid and req_data->password
  24. * which are Wi-Fi AP credentials to which the device will connect */
  25. return ESP_OK;
  26. }
  27. esp_err_t apply_config_handler(wifi_prov_ctx_t **ctx)
  28. {
  29. /* Apply the Wi-Fi STA credentials saved during set_config */
  30. return ESP_OK;
  31. }
  32. /* Structure with various config command handlers to be passed
  33. * as private data during endpoint registration with protocomm */
  34. wifi_prov_config_handlers_t wifi_prov_handlers = {
  35. .get_status_handler = get_status_handler,
  36. .set_config_handler = set_config_handler,
  37. .apply_config_handler = apply_config_handler,
  38. .ctx = NULL
  39. };
  40. /* Set the endpoint handler */
  41. protocomm_add_endpoint(pc, "wifi_config_endpoint",
  42. wifi_prov_config_data_handler,
  43. (void *) &wifi_prov_handlers);
  44. API Reference
  45. -------------
  46. .. include:: /_build/inc/wifi_config.inc