protocol_examples_common.h 2.4 KB

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