Skip to content

Commit 9c857b6

Browse files
tsathishkumarCurclamas
authored andcommitted
[OTA Timeout] Added ability set OTA timeout in the OTA client (espressif#1669)
1 parent dab861a commit 9c857b6

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Diff for: libraries/ArduinoOTA/src/ArduinoOTA.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Update.h"
1010

1111

12-
//#define OTA_DEBUG Serial
12+
// #define OTA_DEBUG Serial
1313

1414
ArduinoOTAClass::ArduinoOTAClass()
1515
: _port(0)
@@ -20,6 +20,7 @@ ArduinoOTAClass::ArduinoOTAClass()
2020
, _size(0)
2121
, _cmd(0)
2222
, _ota_port(0)
23+
, _ota_timeout(1000)
2324
, _start_callback(NULL)
2425
, _end_callback(NULL)
2526
, _error_callback(NULL)
@@ -260,8 +261,9 @@ void ArduinoOTAClass::_runUpdate() {
260261
}
261262

262263
uint32_t written = 0, total = 0, tried = 0;
264+
263265
while (!Update.isFinished() && client.connected()) {
264-
size_t waited = 1000;
266+
size_t waited = _ota_timeout;
265267
size_t available = client.available();
266268
while (!available && waited){
267269
delay(1);
@@ -387,6 +389,10 @@ int ArduinoOTAClass::getCommand() {
387389
return _cmd;
388390
}
389391

392+
void ArduinoOTAClass::setTimeout(int timeoutInMillis) {
393+
_ota_timeout = timeoutInMillis;
394+
}
395+
390396
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA)
391397
ArduinoOTAClass ArduinoOTA;
392-
#endif
398+
#endif

Diff for: libraries/ArduinoOTA/src/ArduinoOTA.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#define INT_BUFFER_SIZE 16
99

10-
1110
typedef enum {
1211
OTA_IDLE,
1312
OTA_WAITAUTH,
@@ -25,9 +24,9 @@ typedef enum {
2524
class ArduinoOTAClass
2625
{
2726
public:
28-
typedef std::function<void(void)> THandlerFunction;
29-
typedef std::function<void(ota_error_t)> THandlerFunction_Error;
30-
typedef std::function<void(unsigned int, unsigned int)> THandlerFunction_Progress;
27+
typedef std::function<void(void)> THandlerFunction;
28+
typedef std::function<void(ota_error_t)> THandlerFunction_Error;
29+
typedef std::function<void(unsigned int, unsigned int)> THandlerFunction_Progress;
3130

3231
ArduinoOTAClass();
3332
~ArduinoOTAClass();
@@ -75,6 +74,8 @@ class ArduinoOTAClass
7574
//Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS
7675
int getCommand();
7776

77+
void setTimeout(int timeoutInMillis);
78+
7879
private:
7980
int _port;
8081
String _password;
@@ -88,6 +89,7 @@ class ArduinoOTAClass
8889
int _size;
8990
int _cmd;
9091
int _ota_port;
92+
int _ota_timeout;
9193
IPAddress _ota_ip;
9294
String _md5;
9395

@@ -106,4 +108,4 @@ class ArduinoOTAClass
106108
extern ArduinoOTAClass ArduinoOTA;
107109
#endif
108110

109-
#endif /* __ARDUINO_OTA_H */
111+
#endif /* __ARDUINO_OTA_H */

0 commit comments

Comments
 (0)