protocol_examples_common.h 2.7 KB

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