Skip to content

Commit

Permalink
Resolved issue #3359 (#6969)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
timstableford authored Feb 23, 2020
1 parent bea64df commit 16319da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
13 changes: 9 additions & 4 deletions doc/ota_updates/readme.rst
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ As shown below, the signed hash is appended to the unsigned binary, followed by

.. code:: bash
NORMAL-BINARY <SIGNED HASH> <uint32 LENGTH-OF-SIGNING-DATA-INCLUDING-THIS-32-BITS>
NORMAL-BINARY <SIGNED HASH> <uint32 LENGTH-OF-SIGNING-DATA-INCLUDING-THIS-32-BITS>
Signed Binary Prerequisites
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -200,11 +200,11 @@ The following chapters provide more details and specific methods for OTA updates
Arduino IDE
-----------

Uploading modules wirelessly from Arduino IDE is intended for the following typical scenarios:
Uploading modules wirelessly from Arduino IDE is intended for the following typical scenarios:

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

- for updating a small number of modules,
- for updating a small number of modules,

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

Expand Down Expand Up @@ -510,6 +510,11 @@ HTTP Server

``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.

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.

There are some cases where you know that you won't be receiving any data but would still like to send progress updates.
It's possible to disable the default behaviour (and keep connections open) by calling closeConnectionsOnUpdate(false).

Requirements
~~~~~~~~~~~~

Expand Down
6 changes: 4 additions & 2 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,10 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&

WiFiClient * tcp = http.getStreamPtr();

WiFiUDP::stopAll();
WiFiClient::stopAllExcept(tcp);
if (_closeConnectionsOnUpdate) {
WiFiUDP::stopAll();
WiFiClient::stopAllExcept(tcp);
}

delay(100);

Expand Down
8 changes: 7 additions & 1 deletion libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class ESP8266HTTPUpdate
_followRedirects = follow;
}

void closeConnectionsOnUpdate(bool sever)
{
_closeConnectionsOnUpdate = sever;
}

void setLedPin(int ledPin = -1, uint8_t ledOn = HIGH)
{
_ledPin = ledPin;
Expand Down Expand Up @@ -146,12 +151,13 @@ class ESP8266HTTPUpdate
// Set the error and potentially use a CB to notify the application
void _setLastError(int err) {
_lastError = err;
if (_cbError) {
if (_cbError) {
_cbError(err);
}
}
int _lastError;
bool _rebootOnUpdate = true;
bool _closeConnectionsOnUpdate = true;
private:
int _httpClientTimeout;
bool _followRedirects;
Expand Down

0 comments on commit 16319da

Please sign in to comment.