WiFi Access Point (AP)

The WiFi access point enables the ESP to host its own WiFi network to which other devices can connect.

API Reference

Header File

Classes

class WifiAp : public espp::BaseComponent

WiFi Access Point (AP)

see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#esp32-wi-fi-ap-general-scenario

WiFi Access Point Example

    espp::WifiAp wifi_ap({.ssid = CONFIG_ESP_WIFI_SSID, .password = CONFIG_ESP_WIFI_PASSWORD});

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.

Public Functions

inline explicit WifiAp(const Config &config)

Initialize the WiFi Access Point (AP)

Parameters:

configWifiAp::Config structure with initialization information.

inline ~WifiAp()

Destructor for the WiFi Access Point (AP)

This will stop the WiFi AP and deinitialize the WiFi subsystem.

inline bool get_saved_config(wifi_config_t &wifi_config)

Get the saved WiFi configuration.

Parameters:

wifi_config – Reference to a wifi_config_t structure to store the configuration.

Returns:

true if the configuration was retrieved successfully, false otherwise.

inline std::string get_mac_address_string()

Get the MAC address of the WiFi Access Point (AP)

Returns:

MAC address of the AP as a string.

inline std::string get_ip_address()

Get the IP address of the WiFi Access Point (AP)

Returns:

IP address of the AP as a string.

inline bool is_connected()

Check if the WiFi Access Point (AP) is connected to a station.

Returns:

True if connected, false otherwise.

inline std::string get_ssid()

Get the SSID of the WiFi Access Point (AP)

Returns:

SSID of the AP as a string.

inline uint8_t get_num_connected_stations()

Get the number of connected stations to this AP.

Returns:

Number of connected stations.

inline std::vector<int> get_connected_station_rssis()

Get the RSSI (Received Signal Strength Indicator) of connected stations.

Returns:

Vector of RSSI values of connected stations.

inline std::vector<std::string> get_connected_station_ips()

Get the IP addresses of connected stations to this AP.

Returns:

Vector of IP addresses of connected stations.

inline bool start()

Start the WiFi Access Point (AP)

Returns:

True if the operation was successful, false otherwise.

inline bool stop()

Stop the WiFi Access Point (AP)

Returns:

True if the operation was successful, false otherwise.

inline bool set_ssid_and_password(const std::string &ssid, const std::string &password)

Set the SSID and password of the WiFi Access Point (AP)

Parameters:
  • ssid – New SSID for the access point.

  • password – New password for the access point. If empty, the AP will be open / have no security.

Returns:

True if the operation was successful, false otherwise.

inline const std::string &get_name() const

Get the name of the component

Note

This is the tag of the logger

Returns:

A const reference to the name of the component

inline void set_log_tag(const std::string_view &tag)

Set the tag for the logger

Parameters:

tag – The tag to use for the logger

inline espp::Logger::Verbosity get_log_level() const

Get the log level for the logger

Returns:

The verbosity level of the logger

inline void set_log_level(espp::Logger::Verbosity level)

Set the log level for the logger

Parameters:

level – The verbosity level to use for the logger

inline void set_log_verbosity(espp::Logger::Verbosity level)

Set the log verbosity for the logger

See also

set_log_level

Note

This is a convenience method that calls set_log_level

Parameters:

level – The verbosity level to use for the logger

inline espp::Logger::Verbosity get_log_verbosity() const

Get the log verbosity for the logger

See also

get_log_level

Note

This is a convenience method that calls get_log_level

Returns:

The verbosity level of the logger

inline void set_log_rate_limit(std::chrono::duration<float> rate_limit)

Set the rate limit for the logger

Note

Only calls to the logger that have _rate_limit suffix will be rate limited

Parameters:

rate_limit – The rate limit to use for the logger

struct Config

Configuration structure for the WiFi Access Point (AP)

Public Members

std::string ssid

SSID for the access point.

std::string password

Password for the access point. If empty, the AP will be open / have no security.

uint8_t channel = {1}

WiFi channel, range [1,13].

uint8_t max_number_of_stations = {4}

Max number of connected stations to this AP.

Logger::Verbosity log_level = {Logger::Verbosity::WARN}

Verbosity of WifiAp logger.

struct Station

Structure representing a connected station.

Public Members

uint8_t mac[6]

MAC address of the connected station.

int rssi

RSSI (Received Signal Strength Indicator) of the connected station.

std::string ip

IP address of the connected station.

Header File

Classes

class WifiApMenu

A CLI menu for interacting with a WiFi Access Point (AP) mode.

This class provides a CLI menu for interacting with a WiFi access point. It provides options for setting the log verbosity, connecting to a WiFi network, disconnecting from a WiFi network, getting the current RSSI (Received Signal Strength Indicator), getting the current IP address, checking if the WiFi is connected, getting the current MAC address, and getting the current WiFi configuration.

Example

    espp::WifiAp wifi_ap({.ssid = "", .password = ""});
    auto ap_menu = espp::WifiApMenu(wifi_ap);
    cli::Cli cli(ap_menu.get());
    cli::SetColor();
    cli.ExitAction([](auto &out) { out << "Goodbye and thanks for all the fish.\n"; });

    espp::Cli input(cli);
    input.SetInputHistorySize(10);
    input.Start();

Public Functions

inline explicit WifiApMenu(std::reference_wrapper<espp::WifiAp> wifi_ap)

Construct a new WifiApMenu object.

Parameters:

wifi_ap – A reference to the WifiAp object to interact with.

inline std::unique_ptr<cli::Menu> get(std::string_view name = "ap", std::string_view description = "WiFi AP menu")

Get the CLI menu for the WiFi access point.

Parameters:
  • name – The name of the menu.

  • description – The description of the menu.

Returns:

A unique pointer to the WiFi AP menu that you can use to add to a CLI.