1
1
#include < chrono>
2
2
#include < vector>
3
3
4
+ #include " sdkconfig.h"
5
+
4
6
#if CONFIG_ESP32_WIFI_NVS_ENABLED
5
7
#include " nvs_flash.h"
6
8
#endif
7
9
8
- #include " sdkconfig.h "
10
+ #include " logger.hpp "
9
11
#include " task.hpp"
10
12
#include " wifi_ap.hpp"
11
13
#include " wifi_sta.hpp"
12
14
15
+ #if defined(CONFIG_COMPILER_CXX_EXCEPTIONS)
16
+ #include " cli.hpp"
17
+ #include " wifi_ap_menu.hpp"
18
+ #include " wifi_sta_menu.hpp"
19
+ #endif
20
+
13
21
using namespace std ::chrono_literals;
14
22
15
23
extern " C" void app_main (void ) {
16
- fmt::print (" Starting WiFi example!\n " );
24
+ espp::Logger logger ({.tag = " wifi_example" , .level = espp::Logger::Verbosity::INFO});
25
+ logger.info (" Starting WiFi example..." );
17
26
18
27
size_t num_seconds_to_run = 2 ;
19
28
@@ -27,38 +36,83 @@ extern "C" void app_main(void) {
27
36
ESP_ERROR_CHECK (ret);
28
37
#endif
29
38
39
+ #if CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
40
+ {
41
+ // ! [wifi sta menu example]
42
+ espp::WifiSta wifi_sta ({.ssid = " " , // CONFIG_ESP_WIFI_SSID,
43
+ .password = " " , // CONFIG_ESP_WIFI_PASSWORD,
44
+ .num_connect_retries = CONFIG_ESP_MAXIMUM_RETRY,
45
+ .on_connected = nullptr ,
46
+ .on_disconnected = nullptr ,
47
+ .on_got_ip =
48
+ [&](ip_event_got_ip_t *eventdata) {
49
+ logger.info (" got IP: {}.{}.{}.{}" ,
50
+ IP2STR (&eventdata->ip_info .ip ));
51
+ },
52
+ .log_level = espp::Logger::Verbosity::DEBUG});
53
+ auto sta_menu = espp::WifiStaMenu (wifi_sta);
54
+ cli::Cli cli (sta_menu.get ());
55
+ cli::SetColor ();
56
+ cli.ExitAction ([](auto &out) { out << " Goodbye and thanks for all the fish.\n " ; });
57
+
58
+ espp::Cli input (cli);
59
+ input.SetInputHistorySize (10 );
60
+ input.Start ();
61
+ // ! [wifi sta menu example]
62
+ }
63
+ #endif // CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
64
+
30
65
{
31
- fmt::print (" Starting WiFi STA example...\n " );
66
+ logger. info (" Starting WiFi STA example..." );
32
67
// ! [wifi sta example]
33
68
espp::WifiSta wifi_sta ({.ssid = CONFIG_ESP_WIFI_SSID,
34
69
.password = CONFIG_ESP_WIFI_PASSWORD,
35
70
.num_connect_retries = CONFIG_ESP_MAXIMUM_RETRY,
36
71
.on_connected = nullptr ,
37
72
.on_disconnected = nullptr ,
38
- .on_got_ip = [](ip_event_got_ip_t *eventdata) {
39
- fmt::print (" got IP: {}.{}.{}.{}\n " , IP2STR (&eventdata->ip_info .ip ));
40
- }});
73
+ .on_got_ip =
74
+ [&](ip_event_got_ip_t *eventdata) {
75
+ logger.info (" got IP: {}.{}.{}.{}" ,
76
+ IP2STR (&eventdata->ip_info .ip ));
77
+ },
78
+ .log_level = espp::Logger::Verbosity::DEBUG});
41
79
42
80
while (!wifi_sta.is_connected ()) {
43
81
std::this_thread::sleep_for (100ms);
44
82
}
45
83
// ! [wifi sta example]
46
84
47
85
std::this_thread::sleep_for (num_seconds_to_run * 1s);
48
- fmt::print (" WiFi STA example complete!\n " );
86
+ logger.info (" WiFi STA example complete!" );
87
+ }
88
+
89
+ #if CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
90
+ {
91
+ // ! [wifi ap menu example]
92
+ espp::WifiAp wifi_ap ({.ssid = " " , .password = " " });
93
+ auto ap_menu = espp::WifiApMenu (wifi_ap);
94
+ cli::Cli cli (ap_menu.get ());
95
+ cli::SetColor ();
96
+ cli.ExitAction ([](auto &out) { out << " Goodbye and thanks for all the fish.\n " ; });
97
+
98
+ espp::Cli input (cli);
99
+ input.SetInputHistorySize (10 );
100
+ input.Start ();
101
+ // ! [wifi ap menu example]
49
102
}
103
+ #endif // CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
50
104
51
105
{
52
- fmt::print (" Starting WiFi AP example...\n " );
106
+ logger. info (" Starting WiFi AP example..." );
53
107
// ! [wifi ap example]
54
108
espp::WifiAp wifi_ap ({.ssid = CONFIG_ESP_WIFI_SSID, .password = CONFIG_ESP_WIFI_PASSWORD});
55
109
// ! [wifi ap example]
56
110
57
111
std::this_thread::sleep_for (num_seconds_to_run * 1s);
58
- fmt::print (" WiFi AP example complete!\n " );
112
+ logger. info (" WiFi AP example complete!" );
59
113
}
60
114
61
- fmt::print (" WiFi example complete!\n " );
115
+ logger. info (" WiFi example complete!" );
62
116
63
117
while (true ) {
64
118
std::this_thread::sleep_for (1s);
0 commit comments