mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Merge branch 'master' into feature/issue-2246-multi-wifi-hidden
This commit is contained in:
@ -138,6 +138,21 @@ GBEnkz4KpKv7TkHoW+j7F5EMcLcSrUIpyw==
|
||||
|
||||
#endif
|
||||
|
||||
#define CACHE_SIZE 5 // Number of sessions to cache.
|
||||
#define USE_CACHE // Enable SSL session caching.
|
||||
// Caching SSL sessions shortens the length of the SSL handshake.
|
||||
// You can see the performance improvement by looking at the
|
||||
// Network tab of the developper tools of your browser.
|
||||
//#define DYNAMIC_CACHE // Whether to dynamically allocate the cache.
|
||||
|
||||
#if defined(USE_CACHE) && defined(DYNAMIC_CACHE)
|
||||
// Dynamically allocated cache.
|
||||
BearSSL::ServerSessions serverCache(CACHE_SIZE);
|
||||
#elif defined(USE_CACHE)
|
||||
// Statically allocated cache.
|
||||
ServerSession store[CACHE_SIZE];
|
||||
BearSSL::ServerSessions serverCache(store, CACHE_SIZE);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@ -169,6 +184,11 @@ void setup() {
|
||||
server.setECCert(serverCertList, BR_KEYTYPE_KEYX|BR_KEYTYPE_SIGN, serverPrivKey);
|
||||
#endif
|
||||
|
||||
// Set the server's cache
|
||||
#if defined(USE_CACHE)
|
||||
server.setCache(&serverCache);
|
||||
#endif
|
||||
|
||||
// Actually start accepting connections
|
||||
server.begin();
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <lwip/napt.h>
|
||||
#include <lwip/dns.h>
|
||||
#include <dhcpserver.h>
|
||||
#include <LwipDhcpServer.h>
|
||||
|
||||
#define NAPT 1000
|
||||
#define NAPT_PORT 10
|
||||
@ -57,8 +57,8 @@ void setup() {
|
||||
WiFi.dnsIP(1).toString().c_str());
|
||||
|
||||
// give DNS servers to AP side
|
||||
dhcps_set_dns(0, WiFi.dnsIP(0));
|
||||
dhcps_set_dns(1, WiFi.dnsIP(1));
|
||||
dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0));
|
||||
dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1));
|
||||
|
||||
WiFi.softAPConfig( // enable AP, with android-compatible google domain
|
||||
IPAddress(172, 217, 28, 254),
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <LwipDhcpServer.h>
|
||||
|
||||
/* Set these to your desired credentials. */
|
||||
const char *ssid = "ESPap";
|
||||
@ -75,8 +76,8 @@ void setup() {
|
||||
...
|
||||
any client not listed will use next IP address available from the range (here 192.168.0.102 and more)
|
||||
*/
|
||||
wifi_softap_add_dhcps_lease(mac_CAM); // always 192.168.0.100
|
||||
wifi_softap_add_dhcps_lease(mac_PC); // always 192.168.0.101
|
||||
dhcpSoftAP.add_dhcps_lease(mac_CAM); // always 192.168.0.100
|
||||
dhcpSoftAP.add_dhcps_lease(mac_PC); // always 192.168.0.101
|
||||
/* Start Access Point. You can remove the password parameter if you want the AP to be open. */
|
||||
WiFi.softAP(ssid, password);
|
||||
Serial.print("AP IP address: ");
|
||||
|
@ -3,43 +3,57 @@
|
||||
The API is almost the same as with the WiFi Shield library,
|
||||
the most obvious difference being the different file you need to include:
|
||||
*/
|
||||
#include "ESP8266WiFi.h"
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("\nESP8266 WiFi scan example"));
|
||||
|
||||
// Set WiFi to station mode and disconnect from an AP if it was previously connected
|
||||
// Set WiFi to station mode
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
// Disconnect from an AP if it was previously connected
|
||||
WiFi.disconnect();
|
||||
delay(100);
|
||||
|
||||
Serial.println("Setup done");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("scan start");
|
||||
String ssid;
|
||||
int32_t rssi;
|
||||
uint8_t encryptionType;
|
||||
uint8_t* bssid;
|
||||
int32_t channel;
|
||||
bool hidden;
|
||||
int scanResult;
|
||||
|
||||
// WiFi.scanNetworks will return the number of networks found
|
||||
int n = WiFi.scanNetworks();
|
||||
Serial.println("scan done");
|
||||
if (n == 0) {
|
||||
Serial.println("no networks found");
|
||||
} else {
|
||||
Serial.print(n);
|
||||
Serial.println(" networks found");
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Print SSID and RSSI for each network found
|
||||
Serial.print(i + 1);
|
||||
Serial.print(": ");
|
||||
Serial.print(WiFi.SSID(i));
|
||||
Serial.print(" (");
|
||||
Serial.print(WiFi.RSSI(i));
|
||||
Serial.print(")");
|
||||
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
|
||||
delay(10);
|
||||
Serial.println(F("Starting WiFi scan..."));
|
||||
|
||||
scanResult = WiFi.scanNetworks(/*async=*/false, /*hidden=*/true);
|
||||
|
||||
if (scanResult == 0) {
|
||||
Serial.println(F("No networks found"));
|
||||
} else if (scanResult > 0) {
|
||||
Serial.printf(PSTR("%d networks found:\n"), scanResult);
|
||||
|
||||
// Print unsorted scan results
|
||||
for (int8_t i = 0; i < scanResult; i++) {
|
||||
WiFi.getNetworkInfo(i, ssid, encryptionType, rssi, bssid, channel, hidden);
|
||||
|
||||
Serial.printf(PSTR(" %02d: [CH %02d] [%02X:%02X:%02X:%02X:%02X:%02X] %ddBm %c %c %s\n"),
|
||||
i,
|
||||
channel,
|
||||
bssid[0], bssid[1], bssid[2],
|
||||
bssid[3], bssid[4], bssid[5],
|
||||
rssi,
|
||||
(encryptionType == ENC_TYPE_NONE) ? ' ' : '*',
|
||||
hidden ? 'H' : 'V',
|
||||
ssid.c_str());
|
||||
delay(0);
|
||||
}
|
||||
} else {
|
||||
Serial.printf(PSTR("WiFi scan error %d"), scanResult);
|
||||
}
|
||||
Serial.println("");
|
||||
|
||||
// Wait a bit before scanning again
|
||||
delay(5000);
|
||||
|
@ -173,10 +173,10 @@ void loop() {
|
||||
|
||||
// determine maximum output size "fair TCP use"
|
||||
// client.availableForWrite() returns 0 when !client.connected()
|
||||
size_t maxToTcp = 0;
|
||||
int maxToTcp = 0;
|
||||
for (int i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
if (serverClients[i]) {
|
||||
size_t afw = serverClients[i].availableForWrite();
|
||||
int afw = serverClients[i].availableForWrite();
|
||||
if (afw) {
|
||||
if (!maxToTcp) {
|
||||
maxToTcp = afw;
|
||||
@ -190,11 +190,11 @@ void loop() {
|
||||
}
|
||||
|
||||
//check UART for data
|
||||
size_t len = std::min((size_t)Serial.available(), maxToTcp);
|
||||
size_t len = std::min(Serial.available(), maxToTcp);
|
||||
len = std::min(len, (size_t)STACK_PROTECTOR);
|
||||
if (len) {
|
||||
uint8_t sbuf[len];
|
||||
size_t serial_got = Serial.readBytes(sbuf, len);
|
||||
int serial_got = Serial.readBytes(sbuf, len);
|
||||
// push UART data to all connected telnet clients
|
||||
for (int i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
// if client.availableForWrite() was 0 (congested)
|
||||
|
Reference in New Issue
Block a user