wifi_provisioning.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. The configuration consists of three commands :
  6. * `get_status` - For querying the Wi-Fi connection status
  7. * `set_config` - For setting the Wi-Fi connection credentials
  8. * `apply_config` - For applying the credentials saved during `set_config` and (re)start the Wi-Fi station
  9. 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`.
  10. Application Example
  11. -------------------
  12. .. highlight:: c
  13. ::
  14. esp_err_t get_status_handler(wifi_prov_config_get_data_t *resp_data)
  15. {
  16. /* Fill the wifi_prov_config_get_data_t structure
  17. * with Wi-Fi station connection status information. */
  18. return ESP_OK;
  19. }
  20. esp_err_t set_config_handler(const wifi_prov_config_set_data_t *req_data)
  21. {
  22. /* Copy contents of req_data->ssid and req_data->password
  23. * which are Wi-Fi AP credentials to which the device will connect */
  24. return ESP_OK;
  25. }
  26. esp_err_t apply_config_handler(void)
  27. {
  28. /* Apply the Wi-Fi STA credentials saved during set_config */
  29. return ESP_OK;
  30. }
  31. /* Structure with various config command handlers to be passed
  32. * as private data during endpoint registration with protocomm */
  33. wifi_prov_config_handlers_t wifi_prov_handlers = {
  34. .get_status_handler = get_status_handler,
  35. .set_config_handler = set_config_handler,
  36. .apply_config_handler = apply_config_handler,
  37. };
  38. /* Set the endpoint handler */
  39. protocomm_add_endpoint(pc, "wifi_config_endpoint",
  40. wifi_prov_config_data_handler,
  41. (void *) &wifi_prov_handlers);
  42. API Reference
  43. -------------
  44. .. include:: /_build/inc/wifi_config.inc