Skip to content

Commit 5f05cf7

Browse files
authored
feat(wifi): Flesh out AP + STA and add menus for control/config (#462)
* feat(wifi): Flesh out AP + STA and add menus for control/config * fix sa * fix example tag
1 parent ef64aca commit 5f05cf7

File tree

10 files changed

+1071
-52
lines changed

10 files changed

+1071
-52
lines changed

components/wifi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
idf_component_register(
22
INCLUDE_DIRS "include"
3-
PRIV_REQUIRES base_component esp_wifi)
3+
PRIV_REQUIRES base_component cli esp_wifi)

components/wifi/example/main/wifi_example.cpp

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
#include <chrono>
22
#include <vector>
33

4+
#include "sdkconfig.h"
5+
46
#if CONFIG_ESP32_WIFI_NVS_ENABLED
57
#include "nvs_flash.h"
68
#endif
79

8-
#include "sdkconfig.h"
10+
#include "logger.hpp"
911
#include "task.hpp"
1012
#include "wifi_ap.hpp"
1113
#include "wifi_sta.hpp"
1214

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+
1321
using namespace std::chrono_literals;
1422

1523
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...");
1726

1827
size_t num_seconds_to_run = 2;
1928

@@ -27,38 +36,83 @@ extern "C" void app_main(void) {
2736
ESP_ERROR_CHECK(ret);
2837
#endif
2938

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+
3065
{
31-
fmt::print("Starting WiFi STA example...\n");
66+
logger.info("Starting WiFi STA example...");
3267
//! [wifi sta example]
3368
espp::WifiSta wifi_sta({.ssid = CONFIG_ESP_WIFI_SSID,
3469
.password = CONFIG_ESP_WIFI_PASSWORD,
3570
.num_connect_retries = CONFIG_ESP_MAXIMUM_RETRY,
3671
.on_connected = nullptr,
3772
.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});
4179

4280
while (!wifi_sta.is_connected()) {
4381
std::this_thread::sleep_for(100ms);
4482
}
4583
//! [wifi sta example]
4684

4785
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]
49102
}
103+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
50104

51105
{
52-
fmt::print("Starting WiFi AP example...\n");
106+
logger.info("Starting WiFi AP example...");
53107
//! [wifi ap example]
54108
espp::WifiAp wifi_ap({.ssid = CONFIG_ESP_WIFI_SSID, .password = CONFIG_ESP_WIFI_PASSWORD});
55109
//! [wifi ap example]
56110

57111
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!");
59113
}
60114

61-
fmt::print("WiFi example complete!\n");
115+
logger.info("WiFi example complete!");
62116

63117
while (true) {
64118
std::this_thread::sleep_for(1s);

components/wifi/idf_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ dependencies:
1818
idf:
1919
version: '>=5.0'
2020
espp/base_component: '>=1.0'
21+
espp/cli: '>=1.0'

0 commit comments

Comments
 (0)