1 /* Common functions for protocol examples, to establish Wi-Fi or Ethernet connection.
2 
3    This example code is in the Public Domain (or CC0 licensed, at your option.)
4 
5    Unless required by applicable law or agreed to in writing, this
6    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7    CONDITIONS OF ANY KIND, either express or implied.
8  */
9 
10 #pragma once
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #include "esp_err.h"
17 #include "esp_netif.h"
18 
19 #ifdef CONFIG_EXAMPLE_CONNECT_ETHERNET
20 #define EXAMPLE_INTERFACE get_example_netif()
21 #endif
22 
23 #ifdef CONFIG_EXAMPLE_CONNECT_WIFI
24 #define EXAMPLE_INTERFACE get_example_netif()
25 #endif
26 
27 #if !defined (CONFIG_EXAMPLE_CONNECT_ETHERNET) && !defined (CONFIG_EXAMPLE_CONNECT_WIFI)
28 // This is useful for some tests which do not need a network connection
29 #define EXAMPLE_INTERFACE NULL
30 #endif
31 
32 /**
33  * @brief Configure Wi-Fi or Ethernet, connect, wait for IP
34  *
35  * This all-in-one helper function is used in protocols examples to
36  * reduce the amount of boilerplate in the example.
37  *
38  * It is not intended to be used in real world applications.
39  * See examples under examples/wifi/getting_started/ and examples/ethernet/
40  * for more complete Wi-Fi or Ethernet initialization code.
41  *
42  * Read "Establishing Wi-Fi or Ethernet Connection" section in
43  * examples/protocols/README.md for more information about this function.
44  *
45  * @return ESP_OK on successful connection
46  */
47 esp_err_t example_connect(void);
48 
49 /**
50  * Counterpart to example_connect, de-initializes Wi-Fi or Ethernet
51  */
52 esp_err_t example_disconnect(void);
53 
54 /**
55  * @brief Configure stdin and stdout to use blocking I/O
56  *
57  * This helper function is used in ASIO examples. It wraps installing the
58  * UART driver and configuring VFS layer to use UART driver for console I/O.
59  */
60 esp_err_t example_configure_stdin_stdout(void);
61 
62 /**
63  * @brief Returns esp-netif pointer created by example_connect()
64  *
65  * @note If multiple interfaces active at once, this API return NULL
66  * In that case the get_example_netif_from_desc() should be used
67  * to get esp-netif pointer based on interface description
68  */
69 esp_netif_t *get_example_netif(void);
70 
71 /**
72  * @brief Returns esp-netif pointer created by example_connect() described by
73  * the supplied desc field
74  *
75  * @param desc Textual interface of created network interface, for example "sta"
76  * indicate default WiFi station, "eth" default Ethernet interface.
77  *
78  */
79 esp_netif_t *get_example_netif_from_desc(const char *desc);
80 
81 #ifdef __cplusplus
82 }
83 #endif
84