File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 99#include " Update.h"
1010
1111
12- // #define OTA_DEBUG Serial
12+ // #define OTA_DEBUG Serial
1313
1414ArduinoOTAClass::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)
391397ArduinoOTAClass ArduinoOTA;
392- #endif
398+ #endif
Original file line number Diff line number Diff line change 77
88#define INT_BUFFER_SIZE 16
99
10-
1110typedef enum {
1211 OTA_IDLE,
1312 OTA_WAITAUTH,
@@ -25,9 +24,9 @@ typedef enum {
2524class 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
106108extern ArduinoOTAClass ArduinoOTA;
107109#endif
108110
109- #endif /* __ARDUINO_OTA_H */
111+ #endif /* __ARDUINO_OTA_H */
You can’t perform that action at this time.
0 commit comments