8000 ArduinoOTA optimizations (#2445) · swarren/esp8266-arduino@889775c · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit 889775c

Browse files
authored
ArduinoOTA optimizations (esp8266#2445)
- Added option to control if the ESP should be rebooted on success - Added delay before ESP.restart() is called - Added some comments to the header
1 parent b412660 commit 889775c

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

libraries/ArduinoOTA/ArduinoOTA.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ArduinoOTAClass::ArduinoOTAClass()
3131
: _port(0)
3232
, _udp_ota(0)
3333
, _initialized(false)
34+
, _rebootOnSuccess(true)
3435
, _state(OTA_IDLE)
3536
, _size(0)
3637
, _cmd(0)
@@ -97,6 +98,10 @@ void ArduinoOTAClass::setPasswordHash(const char * password) {
9798
}
9899
}
99100

101+
void ArduinoOTAClass::setRebootOnSuccess(bool reboot){
102+
_rebootOnSuccess = reboot;
103+
}
104+
100105
void ArduinoOTAClass::begin() {
101106
if (_initialized)
102107
return;
@@ -304,12 +309,19 @@ void ArduinoOTAClass::_runUpdate() {
304309
client.stop();
305310
delay(10);
306311
#ifdef OTA_DEBUG
307-
OTA_DEBUG.printf("Update Success\nRebooting...\n");
312+
OTA_DEBUG.printf("Update Success\n");
308313
#endif
309314
if (_end_callback) {
310315
_end_callback();
311316
}
312-
ESP.restart();
317+
if(_rebootOnSuccess){
318+
#ifdef OTA_DEBUG
319+
OTA_DEBUG.printf("Rebooting...\n");
320+
#endif
321+
//let serial/network finish tasks that might be given in _end_callback
322+
delay(100);
323+
ESP.restart();
324+
}
313325
} else {
314326
_udp_ota->listen(*IP_ADDR_ANY, _port);
315327
if (_error_callback) {

libraries/ArduinoOTA/ArduinoOTA.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,43 @@ class ArduinoOTAClass
3030

3131
ArduinoOTAClass();
3232
~ArduinoOTAClass();
33+
34+
//Sets the service port. Default 8266
3335
void setPort(uint16_t port);
36+
37+
//Sets the device hostname. Default esp8266-xxxxxx
3438
void setHostname(const char *hostname);
3539
String getHostname();
40+
41+
//Sets the password that will be required for OTA. Default NULL
3642
void setPassword(const char *password);
43+
44+
//Sets the password as above but in the form MD5(password). Default NULL
3745
void setPasswordHash(const char *password);
46+
47+
//Sets if the device should be rebooted after successful update. Default true
48+
void setRebootOnSuccess(bool reboot);
49+
50+
//This callback will be called when OTA connection has begun
3851
void onStart(THandlerFunction fn);
52+
53+
//This callback will be called when OTA has finished
3954
void onEnd(THandlerFunction fn);
55+
56+
//This callback will be called when OTA encountered Error
4057
void onError(THandlerFunction_Error fn);
58+
59+
//This callback will be called when OTA is receiving data
4160
void onProgress(THandlerFunction_Progress fn);
61+
62+
//Starts the ArduinoOTA service
4263
void begin();
64+
65+
//Call this in loop() to run the service
4366
void handle();
44-
int getCommand(); // get update command type after OTA started- either U_FLASH or U_SPIFFS
67+
68+
//Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS
69+
int getCommand();
4570

4671
private:
4772
int _port;
@@ -50,6 +75,7 @@ class ArduinoOTAClass
5075
String _nonce;
5176
UdpContext *_udp_ota;
5277
bool _initialized;
78+
bool _rebootOnSuccess;
5379
ota_state_t _state;
5480
int _size;
5581
int _cmd;

0 commit comments

Comments
 (0)
0