protocol_examples_common.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Common functions for protocol examples, to establish Wi-Fi or Ethernet connection.
  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. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include "esp_err.h"
  12. #include "esp_netif.h"
  13. #ifdef CONFIG_EXAMPLE_CONNECT_ETHERNET
  14. #define EXAMPLE_INTERFACE get_example_netif()
  15. #endif
  16. #ifdef CONFIG_EXAMPLE_CONNECT_WIFI
  17. #define EXAMPLE_INTERFACE get_example_netif()
  18. #endif
  19. /**
  20. * @brief Configure Wi-Fi or Ethernet, connect, wait for IP
  21. *
  22. * This all-in-one helper function is used in protocols examples to
  23. * reduce the amount of boilerplate in the example.
  24. *
  25. * It is not intended to be used in real world applications.
  26. * See examples under examples/wifi/getting_started/ and examples/ethernet/
  27. * for more complete Wi-Fi or Ethernet initialization code.
  28. *
  29. * Read "Establishing Wi-Fi or Ethernet Connection" section in
  30. * examples/protocols/README.md for more information about this function.
  31. *
  32. * @return ESP_OK on successful connection
  33. */
  34. esp_err_t example_connect(void);
  35. /**
  36. * Counterpart to example_connect, de-initializes Wi-Fi or Ethernet
  37. */
  38. esp_err_t example_disconnect(void);
  39. /**
  40. * @brief Configure stdin and stdout to use blocking I/O
  41. *
  42. * This helper function is used in ASIO examples. It wraps installing the
  43. * UART driver and configuring VFS layer to use UART driver for console I/O.
  44. */
  45. esp_err_t example_configure_stdin_stdout(void);
  46. /**
  47. * @brief Returns esp-netif pointer created by example_connect()
  48. *
  49. * @note If multiple interfaces active at once, this API return NULL
  50. * In that case the get_example_netif_from_desc() should be used
  51. * to get esp-netif pointer based on interface description
  52. */
  53. esp_netif_t *get_example_netif(void);
  54. /**
  55. * @brief Returns esp-netif pointer created by example_connect() described by
  56. * the supplied desc field
  57. *
  58. * @param desc Textual interface of created network interface, for example "sta"
  59. * indicate default WiFi station, "eth" default Ethernet interface.
  60. *
  61. */
  62. esp_netif_t *get_example_netif_from_desc(const char *desc);
  63. #ifdef __cplusplus
  64. }
  65. #endif