Skip to content

Commit ab9cbf0

Browse files
authored
Merge branch 'master' into toghci
2 parents fcf2a6b + 1134194 commit ab9cbf0

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

doc/esp8266wifi/readme.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The last line will then print out the IP address assigned to the ESP module by `
7878
7979
Serial.println(WiFi.localIP());
8080
81-
If you don't see the last line but just more and more dots ``.........``, then likely name or password to the Wi-Fi network is entered incorrectl in the sketchy. Verify the name and password by connecting from scratch to this Wi-Fi network with a PC or a mobile phone.
81+
If you don't see the last line but just more and more dots ``.........``, then likely name or password to the Wi-Fi network is entered incorrectly in the sketch. Verify the name and password by connecting from scratch to this Wi-Fi network with a PC or a mobile phone.
8282

8383
*Note:* if connection is established, and then lost for some reason, ESP will automatically reconnect to the last used access point once it is again back on-line. This will be done automatically by Wi-Fi library, without any user intervention.
8484

@@ -165,7 +165,7 @@ BearSSL Client Secure and Server Secure
165165
.. figure:: pictures/esp8266-client-secure.png
166166
:alt: ESP8266 operating as the Client Secure
167167

168-
Secure clients and servers require siginificant amounts of additional memory and processing to enable their cryptographic algorithms. In general, only a single secure client or server connection at a time can be processed given the little RAM present on the ESP8266, but there are methods of reducing this RAM requirement detailed in the relevant sections.
168+
Secure clients and servers require significant amounts of additional memory and processing to enable their cryptographic algorithms. In general, only a single secure client or server connection at a time can be processed given the little RAM present on the ESP8266, but there are methods of reducing this RAM requirement detailed in the relevant sections.
169169

170170
`BearSSL::WiFiClientSecure <bearssl-client-secure-class.rst>`__ contains more information on using and configuring TLS connections.
171171

@@ -309,11 +309,11 @@ The tool crawls through all header and source files collecting information from
309309
:alt: Example of documentation for station begin method by Doxygen
310310

311311
.. figure:: pictures/doxygen-example-station-hostname.png
312-
:alt: Example of documentation for station hostname propert by Doxygen
312+
:alt: Example of documentation for station hostname property by Doxygen
313313

314314
If code is not annotated, you will still see the function prototype including types of arguments, and can use provided links to jump straight to the source code to check it out on your own. Doxygen provides really excellent navigation between members of library.
315315

316316
.. figure:: pictures/doxygen-example-udp-begin.png
317-
:alt: Example of documentation for UDP begin method (not annotaed in code)by Doxygen
317+
:alt: Example of documentation for UDP begin method (not annotated in code)by Doxygen
318318

319319
Several classes of `ESP8266WiFi <https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi>`__ are not annotated. When preparing this document, `Doxygen <https://www.doxygen.nl/>`__ has been tremendous help to quickly navigate through almost 30 files that make this library.

doc/esp8266wifi/station-examples.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Station
44
-------
55

6-
Example of connecting to an access point has been shown in chapter `Quick Start <readme.rst#quick-start>`__. In case connection is lost, ESP8266 will automatically reconnect to the last used access point, once it is again available.
6+
Example of connecting to an access point has been shown in chapter `Quick Start <readme.rst#quick-start>`__. In case connection is lost, ESP8266 will automatically reconnect to the last used access point, once it is available again.
77

8-
Can we provide more robust connection to Wi-Fi than that?
8+
Can we provide a more robust connection to Wi-Fi than that?
99

1010
Table of Contents
1111
-----------------
@@ -19,7 +19,7 @@ Table of Contents
1919
Introduction
2020
~~~~~~~~~~~~
2121

22-
Following the example in `Quick Start <readme.rst#quick-start>`__, we would like to go one step further and made ESP connect to next available access point if current connection is lost. This functionality is provided with 'ESP8266WiFiMulti' class and demonstrated in sketch below.
22+
Following the example in `Quick Start <readme.rst#quick-start>`__, we would like to go one step further and make the ESP connect to the next available access point if the current connection is lost. This functionality is provided with the 'ESP8266WiFiMulti' class and demonstrated in the sketch below.
2323

2424
.. code:: cpp
2525
@@ -66,7 +66,7 @@ Following the example in `Quick Start <readme.rst#quick-start>`__, we would like
6666
Prepare Access Points
6767
~~~~~~~~~~~~~~~~~~~~~
6868

69-
To try this sketch in action you need two (or more) access points. In lines below replace ``primary-network-name`` and ``pass-to-primary-network`` with name and password to your primary network. Do the same for secondary network.
69+
To try this sketch in action you need two (or more) access points. In the lines below replace ``primary-network-name`` and ``pass-to-primary-network`` with the name and password to your primary network. Do the same for the secondary network.
7070

7171
.. code:: cpp
7272
@@ -83,7 +83,7 @@ You may add more networks if you have more access points.
8383
Try it Out
8484
~~~~~~~~~~
8585

86-
Now upload updated sketch to ESP module and open serial monitor. Module will first scan for available networks. Then it will select and connect to the network with stronger signal. In case connection is lost, module will connect to next one available.
86+
Now upload the updated sketch to the ESP module and open a serial monitor. The module will first scan for available networks. Then it will select and connect to the network with a stronger signal. In case the connection is lost, the module will connect to the next one available.
8787

8888
This process may look something like:
8989

@@ -93,14 +93,14 @@ This process may look something like:
9393
Looking for WiFi ....... connected to sensor-net-2
9494
Looking for WiFi .... connected to sensor-net-1
9595

96-
In above example ESP connected first to ``sensor-net-1``. Then I have switched ``sensor-net-1`` off. ESP discovered that connection is lost and started searching for another configured network. That happened to be ``sensor-net-2`` so ESP connected to it. Then I have switched ``sensor-net-1`` back on and shut down ``sensor-net-2``. ESP reconnected automatically to ``sensor-net-1``.
96+
In the above example the ESP connects first to ``sensor-net-1``. Then, after I have switched ``sensor-net-1`` off. The ESP discovers that the connection is lost and starts searching for another configured network. That happened to be ``sensor-net-2`` so the ESP connected to it. Then after I have switched ``sensor-net-1`` back on and shut down ``sensor-net-2``. The ESP reconnected automatically to ``sensor-net-1``.
9797

98-
Function ``monitorWiFi()`` is in place to show when connection is lost by displaying ``Looking for WiFi``. Dots ``....`` are displayed during process of searching for another configured access point. Then a message like ``connected to sensor-net-2`` is shown when connection is established.
98+
Function ``monitorWiFi()`` is in place to show when connection is lost by displaying ``Looking for WiFi``. Dots ``....`` are displayed during the process of searching for another configured access point. Then a message like ``connected to sensor-net-2`` is shown when a connection is established.
9999

100100
Can we Make it Simpler?
101101
~~~~~~~~~~~~~~~~~~~~~~~
102102

103-
Please note that you may simplify this sketch by removing function ``monitorWiFi()`` and putting inside ``loop()`` only ``wifiMulti.run()``. ESP will still reconnect between configured access points if required. Now you won't be able to see it on serial monitor unless you add ``Serial.setDebugOutput(true)`` as described in point `Enable Wi-Fi Diagnostic <readme.rst#enable-wi-fi-diagnostic>`__.
103+
Please note that you may simplify this sketch by removing the function ``monitorWiFi()`` and putting inside ``loop()`` only ``wifiMulti.run()``. ESP will still reconnect between configured access points if required. Now you won't be able to see it on serial monitor unless you add ``Serial.setDebugOutput(true)`` as described in point `Enable Wi-Fi Diagnostic <readme.rst#enable-wi-fi-diagnostic>`__.
104104

105105
Updated sketch for such scenario will look as follows:
106106

@@ -127,9 +127,9 @@ Updated sketch for such scenario will look as follows:
127127
wifiMulti.run();
128128
}
129129
130-
That's it! This is really all the code you need to make ESP automatically reconnecting between available networks.
130+
That's it! This is really all the code you need to make ESP automatically reconnect between available networks.
131131

132-
After uploading sketch and opening the serial monitor, the messages will look as below.
132+
After uploading the sketch and opening the serial monitor, the messages will look as below.
133133

134134
*Initial connection to sensor-net-1 on power up:*
135135

@@ -198,8 +198,8 @@ After uploading sketch and opening the serial monitor, the messages will look as
198198
Conclusion
199199
~~~~~~~~~~
200200

201-
I believe the minimalist sketch with ``ESP8266WiFiMulti`` class is a cool example what ESP8266 can do for us behind the scenes with just couple lines of code.
201+
I believe the minimalist sketch with ``ESP8266WiFiMulti`` class is a cool example of what the ESP8266 can do for us behind the scenes with just couple lines of code.
202202

203-
As shown in above example, reconnecting between access points takes time and is not seamless. Therefore, in practical applications, you will likely need to monitor connection status to decide e.g. if you can send the data to external system or should wait until connection is back.
203+
As shown in the above example, reconnecting between access points takes time and is not seamless. Therefore, in practical applications, you will likely need to monitor connection status to decide e.g. if you can send the data to an external system or should wait until the connection is back.
204204

205-
For detailed review of functions provided to manage station mode please refer to the `Station Class <station-class.rst>`__ documentation.
205+
For a detailed review of functions provided to manage station mode please refer to the `Station Class <station-class.rst>`__ documentation.

libraries/ESP8266WebServer/src/detail/RequestHandler.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class RequestHandler {
1010
using WebServerType = ESP8266WebServerTemplate<ServerType>;
1111
public:
1212
virtual ~RequestHandler() { }
13-
virtual bool canHandle(HTTPMethod method, String uri) { (void) method; (void) uri; return false; }
14-
virtual bool canUpload(String uri) { (void) uri; return false; }
15-
virtual bool handle(WebServerType& server, HTTPMethod requestMethod, String requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; }
16-
virtual void upload(WebServerType& server, String requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; }
13+
virtual bool canHandle(HTTPMethod method, const String& uri) { (void) method; (void) uri; return false; }
14+
virtual bool canUpload(const String& uri) { (void) uri; return false; }
15+
virtual bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; }
16+
virtual void upload(WebServerType& server, const String& requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; }
1717

1818
RequestHandler<ServerType>* next() { return _next; }
1919
void next(RequestHandler<ServerType>* r) { _next = r; }

libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ class FunctionRequestHandler : public RequestHandler<ServerType> {
2525
delete _uri;
2626
}
2727

28-
bool canHandle(HTTPMethod requestMethod, String requestUri) override {
28+
bool canHandle(HTTPMethod requestMethod, const String& requestUri) override {
2929
if (_method != HTTP_ANY && _method != requestMethod)
3030
return false;
3131

3232
return _uri->canHandle(requestUri, RequestHandler<ServerType>::pathArgs);
3333
}
3434

35-
bool canUpload(String requestUri) override {
35+
bool canUpload(const String& requestUri) override {
3636
if (!_ufn || !canHandle(HTTP_POST, requestUri))
3737
return false;
3838

3939
return true;
4040
}
4141

42-
bool handle(WebServerType& server, HTTPMethod requestMethod, String requestUri) override {
42+
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) override {
4343
(void) server;
4444
if (!canHandle(requestMethod, requestUri))
4545
return false;
@@ -48,7 +48,7 @@ class FunctionRequestHandler : public RequestHandler<ServerType> {
4848
return true;
4949
}
5050

51-
void upload(WebServerType& server, String requestUri, HTTPUpload& upload) override {
51+
void upload(WebServerType& server, const String& requestUri, HTTPUpload& upload) override {
5252
(void) server;
5353
(void) upload;
5454
if (canUpload(requestUri))
@@ -85,7 +85,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
8585
_baseUriLength = _uri.length();
8686
}
8787

88-
bool canHandle(HTTPMethod requestMethod, String requestUri) override {
88+
bool canHandle(HTTPMethod requestMethod, const String& requestUri) override {
8989
if ((requestMethod != HTTP_GET) && (requestMethod != HTTP_HEAD))
9090
return false;
9191

@@ -95,27 +95,31 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
9595
return true;
9696
}
9797

98-
bool handle(WebServerType& server, HTTPMethod requestMethod, String requestUri) override {
98+
bool handle(WebServerType& server, HTTPMethod requestMethod, const String& requestUri) override {
99+
99100
if (!canHandle(requestMethod, requestUri))
100101
return false;
101102

102103
DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str());
103104

104-
String path(_path);
105+
String path;
106+
path.reserve(_path.length() + requestUri.length() + 32);
107+
path = _path;
105108

106109
if (!_isFile) {
107-
// Base URI doesn't point to a file.
108-
// If a directory is requested, look for index file.
109-
if (requestUri.endsWith("/"))
110-
requestUri += "index.htm";
111110

112111
// Append whatever follows this URI in request to get the file path.
113112
path += requestUri.substring(_baseUriLength);
114113

114+
// Base URI doesn't point to a file.
115+
// If a directory is requested, look for index file.
116+
if (path.endsWith("/"))
117+
path += F("index.htm");
118+
115119
// If neither <blah> nor <blah>.gz exist, and <blah> is a file.htm, try it with file.html instead
116120
// For the normal case this will give a search order of index.htm, index.htm.gz, index.html, index.html.gz
117121
if (!_fs.exists(path) && !_fs.exists(path + ".gz") && path.endsWith(".htm")) {
118-
path += "l";
122+
path += 'l';
119123
}
120124
}
121125
DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile);

0 commit comments

Comments
 (0)