Update README.md

Add example how to scan WiFi Asynchronously
This commit is contained in:
Me No Dev 2016-11-05 12:35:58 +02:00 committed by GitHub
parent 49d5a24815
commit 03c61fab43
1 changed files with 32 additions and 0 deletions

View File

@ -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
```cpp
#include "ESPAsyncTCP.h"