Update README.md
Add example how to scan WiFi Asynchronously
This commit is contained in:
parent
49d5a24815
commit
03c61fab43
32
README.md
32
README.md
|
@ -775,6 +775,38 @@ if (!!window.EventSource) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Scanning for available WiFi Networks
|
||||||
|
```cpp
|
||||||
|
//First request will return 0 results unless you start scan from somewhere else (loop/setup)
|
||||||
|
//Do not request more often than 3-5 seconds
|
||||||
|
server.on("/scan", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
String json = "[";
|
||||||
|
int n = WiFi.scanComplete();
|
||||||
|
if(n == -2){
|
||||||
|
WiFi.scanNetworks(true);
|
||||||
|
} else if(n){
|
||||||
|
for (int i = 0; i < n; ++i){
|
||||||
|
if(i) json += ",";
|
||||||
|
json += "{";
|
||||||
|
json += "\"rssi\":"+String(WiFi.RSSI(i));
|
||||||
|
json += ",\"ssid\":\""+WiFi.SSID(i)+"\"";
|
||||||
|
json += ",\"bssid\":\""+WiFi.BSSIDstr(i)+"\"";
|
||||||
|
json += ",\"channel\":"+String(WiFi.channel(i));
|
||||||
|
json += ",\"secure\":"+String(WiFi.encryptionType(i));
|
||||||
|
json += ",\"hidden\":"+String(WiFi.isHidden(i)?"true":"false");
|
||||||
|
json += "}";
|
||||||
|
}
|
||||||
|
WiFi.scanDelete();
|
||||||
|
if(WiFi.scanComplete() == -2){
|
||||||
|
WiFi.scanNetworks(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json += "]";
|
||||||
|
request->send(200, "text/json", json);
|
||||||
|
json = String();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Setting up the server
|
## Setting up the server
|
||||||
```cpp
|
```cpp
|
||||||
#include "ESPAsyncTCP.h"
|
#include "ESPAsyncTCP.h"
|
||||||
|
|
Loading…
Reference in New Issue