WiFi Access Point (AP)

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

There is an associated menu class espp::WifiApMenu which provides methods to configure the access point settings via a menu interface at runtime.

You can use this class directly, or you can access / manage it via the singleton espp::Wifi class.

API Reference

Header File

Classes

class WifiAp : public espp::WifiBase

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::Config config{.ssid = CONFIG_ESP_WIFI_SSID,
                                .password = CONFIG_ESP_WIFI_PASSWORD,
                                .log_level = espp::Logger::Verbosity::DEBUG};
    espp::WifiAp wifi_ap(config);

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 explicit WifiAp(const Config &config, esp_netif_t *netif)

Initialize the WiFi Access Point (AP)

Parameters:
  • configWifiAp::Config structure with initialization information.

  • netif – Pointer to the AP network interface (obtained from Wifi singleton)

inline ~WifiAp() override

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::vector<uint8_t> get_mac_address()

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

Returns:

MAC address of the AP as a vector of bytes.

inline virtual std::string get_mac_address_string() override

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

Returns:

MAC address of the AP as a string.

inline virtual bool is_connected() const override

Check if any stations are connected to the WiFi Access Point (AP)

Returns:

True if at least one station is connected, false otherwise.

inline virtual std::string get_ssid() override

Get the SSID of the WiFi Access Point (AP)

Returns:

SSID of the AP as a string.

inline uint8_t get_num_connected_stations() const

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 std::vector<Station> get_connected_stations()

Get the connected stations to this AP.

Returns:

Vector of connected stations with their MAC addresses, RSSI and IPs.

inline bool reconfigure(const Config &config)

Reconfigure the WiFi Access Point with a new configuration.

Note

This will stop the AP, apply the new configuration, and restart it.

Parameters:

configWifiAp::Config structure with new AP configuration.

Returns:

True if reconfiguration was successful, false otherwise.

inline virtual bool start() override

Start the WiFi Access Point (AP)

Returns:

True if the operation was successful, false otherwise.

inline virtual bool stop() override

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 std::string get_hostname()

Get the hostname of the WiFi interface.

Returns:

Current hostname as a string

inline virtual bool set_hostname(const std::string &hostname)

Set the hostname of the WiFi interface.

Parameters:

hostname – New hostname to set

Returns:

True if successful, false otherwise

inline virtual std::string get_ip_address()

Get the IP address as a string.

Returns:

IP address as a string

inline esp_netif_t *get_netif() const

Get the network interface pointer.

Returns:

Pointer to the esp_netif_t structure

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.

wifi_phy_rate_t phy_rate{WIFI_PHY_RATE_MCS0_LGI}

PHY rate to use for the access point. Default is MCS0_LGI (6.5

  • 13.5 Mbps Long Guard Interval).

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::Config config{.ssid = "ESP++ WiFi AP", .password = ""};

    espp::WifiAp wifi_ap(config);
    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.