Skip to content

Commit beb81d1

Browse files
committed
[OTA Timeout] Changed to method instead of defined value
1 parent 06fa0b0 commit beb81d1

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

libraries/ArduinoOTA/src/ArduinoOTA.cpp

Lines changed: 9 additions & 3 deletions
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 = OTA_TIMEOUT_DURATION_MS;
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

libraries/ArduinoOTA/src/ArduinoOTA.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
#define INT_BUFFER_SIZE 16
99

10-
#ifndef OTA_TIMEOUT_DURATION_MS
11-
#define OTA_TIMEOUT_DURATION_MS 1000
12-
#endif
13-
1410
typedef enum {
1511
OTA_IDLE,
1612
OTA_WAITAUTH,
@@ -28,9 +24,9 @@ typedef enum {
2824
class ArduinoOTAClass
2925
{
3026
public:
31-
typedef std::function<void(void)> THandlerFunction;
32-
typedef std::function<void(ota_error_t)> THandlerFunction_Error;
33-
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;
3430

3531
ArduinoOTAClass();
3632
~ArduinoOTAClass();
@@ -78,6 +74,8 @@ class ArduinoOTAClass
7874
//Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS
7975
int getCommand();
8076

77+
void setTimeout(int timeoutInMillis);
78+
8179
private:
8280
int _port;
8381
String _password;
@@ -91,6 +89,7 @@ class ArduinoOTAClass
9189
int _size;
9290
int _cmd;
9391
int _ota_port;
92+
int _ota_timeout;
9493
IPAddress _ota_ip;
9594
String _md5;
9695

@@ -109,4 +108,4 @@ class ArduinoOTAClass
109108
extern ArduinoOTAClass ArduinoOTA;
110109
#endif
111110

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

0 commit comments

Comments
 (0)