File tree 2 files changed +16
-8
lines changed
2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 9
9
#include " Update.h"
10
10
11
11
12
- // #define OTA_DEBUG Serial
12
+ // #define OTA_DEBUG Serial
13
13
14
14
ArduinoOTAClass::ArduinoOTAClass ()
15
15
: _port(0 )
@@ -20,6 +20,7 @@ ArduinoOTAClass::ArduinoOTAClass()
20
20
, _size(0 )
21
21
, _cmd(0 )
22
22
, _ota_port(0 )
23
+ , _ota_timeout(1000 )
23
24
, _start_callback(NULL )
24
25
, _end_callback(NULL )
25
26
, _error_callback(NULL )
@@ -260,8 +261,9 @@ void ArduinoOTAClass::_runUpdate() {
260
261
}
261
262
262
263
uint32_t written = 0 , total = 0 , tried = 0 ;
264
+
263
265
while (!Update.isFinished () && client.connected ()) {
264
- size_t waited = 1000 ;
266
+ size_t waited = _ota_timeout ;
265
267
size_t available = client.available ();
266
268
while (!available && waited){
267
269
delay (1 );
@@ -387,6 +389,10 @@ int ArduinoOTAClass::getCommand() {
387
389
return _cmd;
388
390
}
389
391
392
+ void ArduinoOTAClass::setTimeout (int timeoutInMillis) {
393
+ _ota_timeout = timeoutInMillis;
394
+ }
395
+
390
396
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_ARDUINOOTA)
391
397
ArduinoOTAClass ArduinoOTA;
392
- #endif
398
+ #endif
Original file line number Diff line number Diff line change 7
7
8
8
#define INT_BUFFER_SIZE 16
9
9
10
-
11
10
typedef enum {
12
11
OTA_IDLE,
13
12
OTA_WAITAUTH,
@@ -25,9 +24,9 @@ typedef enum {
25
24
class ArduinoOTAClass
26
25
{
27
26
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;
31
30
32
31
ArduinoOTAClass ();
33
32
~ArduinoOTAClass ();
@@ -75,6 +74,8 @@ class ArduinoOTAClass
75
74
// Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS
76
75
int getCommand ();
77
76
77
+ void setTimeout (int timeoutInMillis);
78
+
78
79
private:
79
80
int _port;
80
81
String _password;
@@ -88,6 +89,7 @@ class ArduinoOTAClass
88
89
int _size;
89
90
int _cmd;
90
91
int _ota_port;
92
+ int _ota_timeout;
91
93
IPAddress _ota_ip;
92
94
String _md5;
93
95
@@ -106,4 +108,4 @@ class ArduinoOTAClass
106
108
extern ArduinoOTAClass ArduinoOTA;
107
109
#endif
108
110
109
- #endif /* __ARDUINO_OTA_H */
111
+ #endif /* __ARDUINO_OTA_H */
You can’t perform that action at this time.
0 commit comments