Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions components/dns_server/example/main/dns_server_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ extern "C" void app_main(void) {

logger.info("Starting DNS Server Example");

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

// Initialize WiFi in AP mode
std::string ap_ssid = "ESP-DNS-Test";
std::string ap_password = "testpassword";
Expand Down
14 changes: 0 additions & 14 deletions components/ftp/example/main/ftp_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <iterator>
#include <thread>

#if CONFIG_ESP32_WIFI_NVS_ENABLED
#include "nvs_flash.h"
#endif

#include "logger.hpp"
#include "task.hpp"
#include "wifi_sta.hpp"
Expand All @@ -23,16 +19,6 @@ extern "C" void app_main(void) {

logger.info("Stating socket example!");

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

std::string ip_address;
espp::WifiSta wifi_sta({.ssid = CONFIG_ESP_WIFI_SSID,
.password = CONFIG_ESP_WIFI_PASSWORD,
Expand Down
14 changes: 0 additions & 14 deletions components/iperf_menu/example/main/iperf_menu_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#include "sdkconfig.h"

#if CONFIG_ESP32_WIFI_NVS_ENABLED
#include "nvs_flash.h"
#endif

#include "logger.hpp"
#include "task.hpp"
#include "wifi_sta.hpp"
Expand All @@ -20,16 +16,6 @@ extern "C" void app_main(void) {
espp::Logger logger({.tag = "iperf_example", .level = espp::Logger::Verbosity::INFO});
logger.info("Starting example...");

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

{
//! [iperf menu example]
espp::WifiSta wifi_sta({.ssid = "", // CONFIG_ESP_WIFI_SSID,
Expand Down
10 changes: 0 additions & 10 deletions components/ping/example/main/ping_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ extern "C" void app_main(void) {
espp::Logger logger({.tag = "ping_example", .level = espp::Logger::Verbosity::INFO});
logger.info("Starting Ping example...");

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

{
//! [ping_cli_example]
// Simple WiFi STA bring-up assumed configured via menu
Expand Down
11 changes: 0 additions & 11 deletions components/remote_debug/example/main/remote_debug_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "file_system.hpp"
#include "logger.hpp"
#include "nvs.hpp"
#include "remote_debug.hpp"
#include "timer.hpp"
#include "wifi_sta.hpp"
Expand All @@ -16,16 +15,6 @@ extern "C" void app_main(void) {

logger.info("Starting Remote Debug Example");

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

// Initialize filesystem
logger.info("Initializing filesystem...");
auto &fs = espp::FileSystem::get();
Expand Down
14 changes: 0 additions & 14 deletions components/rtsp/example/main/rtsp_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

#include "sdkconfig.h"

#if CONFIG_ESP32_WIFI_NVS_ENABLED
#include "nvs_flash.h"
#endif

#include "logger.hpp"
#include "task.hpp"
#include "wifi_sta.hpp"
Expand All @@ -27,16 +23,6 @@ extern "C" void app_main(void) {

logger.info("Starting RTSP example!");

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

std::string ip_address;
espp::WifiSta wifi_sta({.ssid = CONFIG_ESP_WIFI_SSID,
.password = CONFIG_ESP_WIFI_PASSWORD,
Expand Down
14 changes: 0 additions & 14 deletions components/socket/example/main/socket_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <iterator>
#include <thread>

#if CONFIG_ESP32_WIFI_NVS_ENABLED
#include "nvs_flash.h"
#endif

#include "logger.hpp"
#include "task.hpp"
#include "tcp_socket.hpp"
Expand All @@ -22,16 +18,6 @@ extern "C" void app_main(void) {

auto test_duration = 3s;

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

// create a wifi access point here so that LwIP will be init for this example
espp::WifiAp wifi_ap({.ssid = "SocketExample",
.password = "", // no security
Expand Down
2 changes: 1 addition & 1 deletion components/wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src"
REQUIRES esp_wifi nvs_flash base_component cli)
REQUIRES esp_wifi nvs base_component cli)
Comment thread
finger563 marked this conversation as resolved.
14 changes: 0 additions & 14 deletions components/wifi/example/main/wifi_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

#include "sdkconfig.h"

#if CONFIG_ESP32_WIFI_NVS_ENABLED
#include "nvs_flash.h"
#endif

#include "logger.hpp"
#include "task.hpp"
#include "wifi.hpp"
Expand Down Expand Up @@ -35,16 +31,6 @@ extern "C" void app_main(void) {

size_t num_seconds_to_run = 2;

#if CONFIG_ESP32_WIFI_NVS_ENABLED
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#endif

{
//! [wifi sta menu example]
espp::WifiSta::Config config{.ssid = "", // use whatever was saved to NVS (if any)
Expand Down
1 change: 1 addition & 0 deletions components/wifi/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ dependencies:
version: '>=5.0'
espp/base_component: '>=1.0'
espp/cli: '>=1.0'
espp/nvs: '>=1.0'
19 changes: 18 additions & 1 deletion components/wifi/include/wifi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "wifi_format_helpers.hpp"
#include "wifi_sta.hpp"

#if CONFIG_ESP32_WIFI_NVS_ENABLED
#include "nvs.hpp"
#endif
Comment thread
finger563 marked this conversation as resolved.

namespace espp {

/// @brief The Wifi class provides access to the ESP32 Wifi functionality.
Expand Down Expand Up @@ -568,7 +572,17 @@ class Wifi : public espp::BaseComponent {
/// @details The Wifi object is a singleton object and can only be
/// constructed once. WiFi stack initialization is deferred to init().
Wifi()
: BaseComponent("Wifi") {}
: BaseComponent("Wifi") {
#if CONFIG_ESP32_WIFI_NVS_ENABLED
std::error_code ec;
nvs_.init(ec);
if (ec) {
logger_.error("Failed to initialize NVS for WiFi credentials: {}", ec.message());
} else {
logger_.info("NVS initialized for WiFi credentials");
}
#endif
}

/// @brief Destructor - cleans up WiFi stack.
~Wifi() {
Expand Down Expand Up @@ -678,6 +692,9 @@ class Wifi : public espp::BaseComponent {
return true;
}

#if CONFIG_ESP32_WIFI_NVS_ENABLED
espp::Nvs nvs_; ///< NVS instance used to initialize NVS when WiFi NVS support is enabled
#endif
mutable std::recursive_mutex mutex_; ///< Mutex for thread-safe access to configs and state
std::unordered_map<std::string, WifiAp::Config> ap_configs_;
std::unordered_map<std::string, WifiSta::Config> sta_configs_;
Expand Down
5 changes: 0 additions & 5 deletions components/wifi/include/wifi_ap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "esp_mac.h"
#include "esp_wifi.h"
#include "esp_wifi_ap_get_sta_list.h"
#include "nvs_flash.h"

#include "base_component.hpp"
#include "wifi_base.hpp"
Expand All @@ -19,10 +18,6 @@ namespace espp {
* see
* https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#esp32-wi-fi-ap-general-scenario
*
* @note If CONFIG_ESP32_WIFI_NVS_ENABLED is set to `y` (which is the
* default), then you must ensure that you call `nvs_flash_init()`
* prior to creating the WiFi Access Point.
*
* \section wifiap_ex1 WiFi Access Point Example
* \snippet wifi_example.cpp wifi ap example
*/
Expand Down
5 changes: 0 additions & 5 deletions components/wifi/include/wifi_sta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "esp_event.h"
#include "esp_mac.h"
#include "esp_wifi.h"
#include "nvs_flash.h"

#include "base_component.hpp"
#include "wifi_base.hpp"
Expand All @@ -21,10 +20,6 @@ namespace espp {
* see
* https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#esp32-wi-fi-station-general-scenario
*
* @note If CONFIG_ESP32_WIFI_NVS_ENABLED is set to `y` (which is the
* default), then you must ensure that you call `nvs_flash_init()`
* prior to creating the WiFi Station.
*
* \section wifista_ex1 WiFi Station Example
* \snippet wifi_example.cpp wifi sta example
*/
Expand Down
Loading