Skip to content

Commit 16319da

Browse files
Resolved issue #3359 (#6969)
* Resolved issue #3359 Made severing connections optional as per the patch in the issue. Also fixed a minor spacing issue. * Renamed sever to close and added information to readme Also my editor automatically removed some odd whitespace at the end of a few lines.
1 parent bea64df commit 16319da

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

doc/ota_updates/readme.rst

100644100755
+9-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ As shown below, the signed hash is appended to the unsigned binary, followed by
6161

6262
.. code:: bash
6363
64-
NORMAL-BINARY <SIGNED HASH> <uint32 LENGTH-OF-SIGNING-DATA-INCLUDING-THIS-32-BITS>
64+
NORMAL-BINARY <SIGNED HASH> <uint32 LENGTH-OF-SIGNING-DATA-INCLUDING-THIS-32-BITS>
6565
6666
Signed Binary Prerequisites
6767
^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -200,11 +200,11 @@ The following chapters provide more details and specific methods for OTA updates
200200
Arduino IDE
201201
-----------
202202

203-
Uploading modules wirelessly from Arduino IDE is intended for the following typical scenarios:
203+
Uploading modules wirelessly from Arduino IDE is intended for the following typical scenarios:
204204

205-
- during firmware development as a quicker alternative to loading over a serial port,
205+
- during firmware development as a quicker alternative to loading over a serial port,
206206

207-
- for updating a small number of modules,
207+
- for updating a small number of modules,
208208

209209
- only if modules are accessible on the same network as the computer with the Arduino IDE.
210210

@@ -510,6 +510,11 @@ HTTP Server
510510

511511
``ESPhttpUpdate`` class can check for updates and download a binary file from HTTP web server. It is possible to download updates from every IP or domain address on the network or Internet.
512512

513+
Note that by default this class closes all other connections except the one used by the update, this is because the update method blocks. This means that if there's another application receiving data then TCP packets will build up in the buffer leading to out of memory errors causing the OTA update to fail. There's also a limited number of receive buffers available and all may be used up by other applications.
514+
515+
There are some cases where you know that you won't be receiving any data but would still like to send progress updates.
516+
It's possible to disable the default behaviour (and keep connections open) by calling closeConnectionsOnUpdate(false).
517+
513518
Requirements
514519
~~~~~~~~~~~~
515520

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

100644100755
+4-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,10 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
345345

346346
WiFiClient * tcp = http.getStreamPtr();
347347

348-
WiFiUDP::stopAll();
349-
WiFiClient::stopAllExcept(tcp);
348+
if (_closeConnectionsOnUpdate) {
349+
WiFiUDP::stopAll();
350+
WiFiClient::stopAllExcept(tcp);
351+
}
350352

351353
delay(100);
352354

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h

100644100755
+7-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class ESP8266HTTPUpdate
8787
_followRedirects = follow;
8888
}
8989

90+
void closeConnectionsOnUpdate(bool sever)
91+
{
92+
_closeConnectionsOnUpdate = sever;
93+
}
94+
9095
void setLedPin(int ledPin = -1, uint8_t ledOn = HIGH)
9196
{
9297
_ledPin = ledPin;
@@ -146,12 +151,13 @@ class ESP8266HTTPUpdate
146151
// Set the error and potentially use a CB to notify the application
147152
void _setLastError(int err) {
148153
_lastError = err;
149-
if (_cbError) {
154+
if (_cbError) {
150155
_cbError(err);
151156
}
152157
}
153158
int _lastError;
154159
bool _rebootOnUpdate = true;
160+
bool _closeConnectionsOnUpdate = true;
155161
private:
156162
int _httpClientTimeout;
157163
bool _followRedirects;

0 commit comments

Comments
 (0)