Example Usage

// Basic
App.init_wifi("YOUR_SSID", "YOUR_PASSWORD");
// Manual IP
auto *wifi = App.init_wifi("YOUR_SSID", "YOUR_PASSWORD");
    .static_ip = IPAddress(192, 168, 178, 42),
    .gateway = IPAddress(192, 168, 178, 1),
    .subnet = IPAddress(255, 255, 255, 0)
// AP
wifi->set_ap("AP SSID", "Optional AP Password");

API Reference


class WiFiComponent : public Component

This component is responsible for managing the ESP WiFi interface.

Public Functions


Construct a WiFiComponent.

void set_sta(const WiFiAp &ap)

Setup the STA (client) mode. The parameters define which station to connect to.

void set_ap(const WiFiAp &ap)

Setup an Access Point that should be created if no connection to a station can be made.

This can also be used without set_sta(). Then the AP will always be active.

If both STA and AP are defined, then both will be enabled at startup, but if a connection to a station can be made, the AP will be turned off again.

void set_hostname(std::string &&hostname)

Set the advertised hostname, defaults to the App name.

const std::string &get_hostname()
void start_connecting()
void check_connecting_finished()
void retry_connect()
bool can_proceed()
void set_reboot_timeout(uint32_t reboot_timeout)
bool is_connected()
void set_power_save_mode(WiFiPowerSaveMode power_save)

Set the power save option for the WiFi interface.

Options are:

  • WIFI_POWER_SAVE_NONE (default, least power saving)
  • WIFI_POWER_SAVE_HIGH (try to save as much power as possible)

Note that this can affect WiFi performance, for example a higher power saving option can increase the amount of random disconnects from the WiFi router.

  • power_save: The power save mode.

void setup()

Setup WiFi interface.

void dump_config()
float get_setup_priority() const

WIFI setup_priority.

float get_loop_priority() const

priority of loop().

higher -> executed earlier

Defaults to 0.

The loop priority of this component

void loop()

Reconnect WiFi if required.

bool has_sta() const
bool has_ap() const

Protected Functions

void setup_ap_config()
void print_connect_params_()
void on_wifi_event(system_event_id_t event, system_event_info_t info)

Used for logging WiFi events.

void handle_error_from_callback()

Protected Attributes

std::string hostname_
WiFiAp sta_
WiFiAp ap_
WiFiComponentState state_ = {WIFI_COMPONENT_STATE_OFF}
uint32_t action_started_
uint8_t num_retried_ = {0}
uint32_t last_connected_ = {0}
uint32_t reboot_timeout_ = {300000}
WiFiPowerSaveMode power_save_ = {WIFI_POWER_SAVE_NONE}
optional<uint32_t> cooldown_reconnect_ = {}
bool error_from_callback_ = {false}
struct ManualIP

Struct for setting static IPs in WiFiComponent.

Public Members

IPAddress static_ip
IPAddress gateway
IPAddress subnet
IPAddress dns1

The first DNS server. for default.

IPAddress dns2

The second DNS server. for default.