8000 [OTA] Add UserSelectable timeout for invitation to device + check for… · tellebook/arduino-esp32@7b243ad · 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

Commit 7b243ad

Browse files
tsathishkumarme-no-dev
authored andcommitted
[OTA] Add UserSelectable timeout for invitation to device + check for OK result in the last few messages (espressif#1445)
1 parent 03808e3 commit 7b243ad

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

tools/espota.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
106106
sock2.close()
107107
logging.error('Host %s Not Found', remoteAddr)
108108
return 1
109-
sock2.settimeout(1)
109+
sock2.settimeout(TIMEOUT)
110110
try:
111111
data = sock2.recv(37).decode()
112112
break;
@@ -162,7 +162,6 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
162162
logging.error('No response from device')
163163
sock.close()
164164
return 1
165-
166165
try:
167166
f = open(filename, "rb")
168167
if (PROGRESS):
@@ -191,18 +190,26 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
191190
sys.stderr.write('\n')
192191
logging.info('Waiting for result...')
193192
try:
194-
connection.settimeout(60)
195-
data = connection.recv(32).decode()
196-
logging.info('Result: %s' ,data)
197-
connection.close()
198-
f.close()
199-
sock.close()
200-
if (data != "OK"):
201-
sys.stderr.write('\n')
202-
logging.error('%s', data)
203-
return 1;
204-
return 0
205-
except:
193+
count = 0
194+
while True:
195+
count=count+1
196+
connection.settimeout(60)
197+
data = connection.recv(32).decode()
198+
logging.info('Result: %s' ,data)
199+
200+
if data == "OK":
201+
logging.info('Success')
202+
connection.close()
203+
f.close()
204+
sock.close()
205+
return 0;
206+
if count == 5:
207+
logging.error('Error response from device')
208+
connection.close()
209+
f.close()
210+
sock.close()
211+
return 1
212+
except e:
206213
logging.error('No Result!')
207214
connection.close()
208215
C1A3 f.close()
@@ -292,6 +299,12 @@ def parser(unparsed_args):
292299
action = "store_true",
293300
default = False
294301
)
302+
group.add_option("-t", "--timeout",
303+
dest = "timeout",
304+
type = "int",
305+
help = "Timeout to wait for the ESP8266 to accept invitation",
306+
default = 10
307+
)
295308
parser.add_option_group(group)
296309

297310
(options, args) = parser.parse_args(unparsed_args)
@@ -312,6 +325,10 @@ def main(args):
312325
# check options
313326
global PROGRESS
314327
PROGRESS = options.progress
328+
329+
global TIMEOUT
330+
TIMEOUT = options.timeout
331+
315332
if (not options.esp_ip or not options.image):
316333
logging.critical("Not enough arguments.")
317334
return 1

0 commit comments

Comments
 (0)
0