WiFi Events

group wifi_ev

Event callback interface for WiFi events.

WiFi Station Interface
WiFi Access Point



Common set of reason codes to IEEE 802.11-2007.

Some acronymns used here - see the full standard for more precise definitions.

  • SSID: Service Set Identifier (the visible name given to an Access Point)
  • BSSID: Basic Service Set Identifier (a MAC address physically identifying the AP)
  • IE: Information Element (standard piece of information carried within WiFi packets)
  • STA: Station (any device which supports WiFi, including APs though the term commonly refers to a client)
  • AP: Access Point (device to which other stations may be associated)
  • RSN: Robust Security Network
  • AUTH: Authentication (how a station proves its identity to another)
Codes at 200+ are non-standard, defined by Espressif.


typedef Delegate<void(const String &ssid, MacAddress bssid, uint8_t channel)> StationConnectDelegate

Delegate type for ‘station connected’ event.

This event occurs when the station successfully connects to the target AP. Upon receiving this event, the DHCP client begins the process of getting an IP address.
  • ssid:
  • bssid:
  • channel:

typedef Delegate<void(const String &ssid, MacAddress bssid, WifiDisconnectReason reason)> StationDisconnectDelegate

Delegate type for ‘station disconnected’ event.

This event can be generated in the following scenarios:
  • When the station is already connected to the AP, and a manual disconnect or re-configuration is taking place. e.g. WifiStation.disconnect()
  • When WifiStation.connect() is called, but the Wi-Fi driver fails to set up a connection with the AP due to certain reasons, e.g. the scan fails to find the target AP, authentication times out, etc. If there are more than one AP with the same SSID, the disconnected event is raised after the station fails to connect all of the found APs.
  • When the Wi-Fi connection is disrupted because of specific reasons, e.g., the station continuously loses N beacons, the AP kicks off the station, the AP’s authentication mode is changed, etc.
  • ssid: SSID from which we’ve disconnected
  • bssid:
  • reason: Why the connection was dropped

typedef Delegate<void(WifiAuthMode oldMode, WifiAuthMode newMode)> StationAuthModeChangeDelegate

Delegate type for ‘station authorisation mode changed’ event.

This event arises when the AP to which the station is connected changes its authentication mode, e.g., from ‘no auth’ to WPA. Generally, the application event callback does not need to handle this.
  • oldMode:
  • newMode:

typedef Delegate<void(IpAddress ip, IpAddress netmask, IpAddress gateway)> StationGotIPDelegate

Delegate type for ‘station got IP address’ event.

This event arises when the DHCP client successfully gets the IPV4 address from the DHCP server, or when the IPV4 address is changed. The IPV4 may be changed because of the following reasons:
  • The DHCP client fails to renew/rebind the IPV4 address, and the station’s IPV4 is reset to 0.
  • The DHCP client rebinds to a different address.
  • The static-configured IPV4 address is changed.
  • ip:
  • netmask:
  • gateway:

typedef Delegate<void(MacAddress mac, uint16_t aid)> AccessPointConnectDelegate

Delegate type for ‘Access Point Connect’ event.

This event occurs every time a station is connected to our Access Point.
  • mac: MAC address of the station
  • aid: Association ID representing the connected station

typedef Delegate<void(MacAddress mac, uint16_t aid)> AccessPointDisconnectDelegate

Delegate type for ‘Access Point Disconnect’ event.

This event occurs every time a station is disconnected from our Access Point.
  • mac: MAC address of the station
  • aid: Association ID assigned to the station

typedef Delegate<void(int rssi, MacAddress mac)> AccessPointProbeReqRecvedDelegate

Delegate type for ‘Access Point Probe Request Received’ event.

Probe Requests are a low-level management frame which are used to determine informaton about our Access Point, such as which authentication modes are supported.
  • rssi: Signal strength
  • mac:


enum WifiDisconnectReason

Reason codes for WiFi station disconnection.




WifiEventsClass &WifiEvents

Global reference to architecture-specific implementation.

class WifiEventsClass
#include <WifiEvents.h>

WiFi events class.

Public Functions

void onStationConnect(StationConnectDelegate delegateFunction)

Set callback for ‘station connected’ event.

void onStationDisconnect(StationDisconnectDelegate delegateFunction)

Set callback for ‘station disconnected’ event.

void onStationAuthModeChange(StationAuthModeChangeDelegate delegateFunction)

Set callback for ‘station authorisation mode change’ event.

void onStationGotIP(StationGotIPDelegate delegateFunction)

Set callback for ‘station connected with IP address’ event.

void onAccessPointConnect(AccessPointConnectDelegate delegateFunction)

Set callback for ‘access point client connected’ event.

void onAccessPointDisconnect(AccessPointDisconnectDelegate delegateFunction)

Set callback for ‘access point client disconnected’ event.

void onAccessPointProbeReqRecved(AccessPointProbeReqRecvedDelegate delegateFunction)

Set callback for ‘access point probe request received’ event.

Public Static Functions

static String getDisconnectReasonName(WifiDisconnectReason reason)

Get short name for disconnection reason.

static String getDisconnectReasonDesc(WifiDisconnectReason reason)

Get descriptive explanation for disconnect reason.