mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
ESP8266WiFi - document event handler lifetime, add [[nodiscard]] (#9087)
* disallow not assigning wifieventhandler somewhere * fix markdown syntax in rst * mention lifetime in example and docs
This commit is contained in:
@ -24,6 +24,9 @@
|
||||
const char* ssid = APSSID;
|
||||
const char* password = APPSK;
|
||||
|
||||
// WiFi.on* methods **must** only be called **after** entering setup().
|
||||
// Assigning immediately in global scope is not adviced, neither is assigning them within any other object constructors.
|
||||
// These variables **may** exist in function block, but **only** if they are declared as `static`
|
||||
WiFiEventHandler stationConnectedHandler;
|
||||
WiFiEventHandler stationDisconnectedHandler;
|
||||
WiFiEventHandler probeRequestPrintHandler;
|
||||
@ -43,12 +46,12 @@ void setup() {
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAP(ssid, password);
|
||||
|
||||
// Register event handlers.
|
||||
// Callback functions will be called as long as these handler objects exist.
|
||||
// Call "onStationConnected" each time a station connects
|
||||
stationConnectedHandler = WiFi.onSoftAPModeStationConnected(&onStationConnected);
|
||||
|
||||
// Call "onStationDisconnected" each time a station disconnects
|
||||
stationDisconnectedHandler = WiFi.onSoftAPModeStationDisconnected(&onStationDisconnected);
|
||||
|
||||
// Call "onProbeRequestPrint" and "onProbeRequestBlink" each time
|
||||
// a probe request is received.
|
||||
// Former will print MAC address of the station and RSSI to Serial,
|
||||
|
Reference in New Issue
Block a user