Skip to content

Commit 9c347d2

Browse files
committed
doc
1 parent 2ec27c6 commit 9c347d2

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

doc/esp8266wifi/station-examples.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Table of Contents
1414
- `Prepare Access Points <#prepare-access-points>`__
1515
- `Try it Out <#try-it-out>`__
1616
- `Can we Make it Simpler? <#can-we-make-it-simpler>`__
17+
- `Per-SSID configuration`__
1718
- `Conclusion <#conclusion>`__
1819

1920
Introduction
@@ -195,6 +196,36 @@ After uploading the sketch and opening the serial monitor, the messages will loo
195196
dhcp client start...
196197
ip:192.168.1.10,mask:255.255.255.0,gw:192.168.1.9
197198

199+
200+
Per-SSID configuration
201+
~~~~~~~~~~~~~~~~~~~~~~~
202+
203+
Whenever network SSID is selected by the 'ESP8266WiFiMulti', it can be instructed to call a user function before connection is attempted.
204+
205+
For example, to allow static IP configuration, declare the following function
206+
207+
.. code:: cpp
208+
209+
void onSSIDSelected(const char *ssid) {
210+
if (strcmp(ssid, "sensor-net-2") == 0) {
211+
IPAddress ip(10, 0, 0, 2);
212+
IPAddress gw(10, 0, 0, 1);
213+
IPAddress subnet(255, 255, 255, 0);
214+
WiFi.config(ip, gw, subnet);
215+
return;
216+
}
217+
218+
// revert to DHCP configuration
219+
WiFi.config(0U, 0U, 0U);
220+
}
221+
222+
Then, register it after ``addAP(...)`` lines
223+
224+
.. code:: cpp
225+
226+
wifiMulti.onSSIDSelected(onSSIDSelected);
227+
228+
198229
Conclusion
199230
~~~~~~~~~~
200231

0 commit comments

Comments
 (0)