[OTA] Add UserSelectable timeout for invitation to device + check for OK result in the last few messages (#1445)

This commit is contained in:
Sathishkumar T 2018-05-31 18:59:53 +05:30 committed by Me No Dev
parent 03808e3b8b
commit 7b243adcfd

View File

@ -106,7 +106,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
sock2.close() sock2.close()
logging.error('Host %s Not Found', remoteAddr) logging.error('Host %s Not Found', remoteAddr)
return 1 return 1
sock2.settimeout(1) sock2.settimeout(TIMEOUT)
try: try:
data = sock2.recv(37).decode() data = sock2.recv(37).decode()
break; break;
@ -162,7 +162,6 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
logging.error('No response from device') logging.error('No response from device')
sock.close() sock.close()
return 1 return 1
try: try:
f = open(filename, "rb") f = open(filename, "rb")
if (PROGRESS): if (PROGRESS):
@ -191,18 +190,26 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
sys.stderr.write('\n') sys.stderr.write('\n')
logging.info('Waiting for result...') logging.info('Waiting for result...')
try: try:
connection.settimeout(60) count = 0
data = connection.recv(32).decode() while True:
logging.info('Result: %s' ,data) count=count+1
connection.close() connection.settimeout(60)
f.close() data = connection.recv(32).decode()
sock.close() logging.info('Result: %s' ,data)
if (data != "OK"):
sys.stderr.write('\n') if data == "OK":
logging.error('%s', data) logging.info('Success')
return 1; connection.close()
return 0 f.close()
except: sock.close()
return 0;
if count == 5:
logging.error('Error response from device')
connection.close()
f.close()
sock.close()
return 1
except e:
logging.error('No Result!') logging.error('No Result!')
connection.close() connection.close()
f.close() f.close()
@ -292,6 +299,12 @@ def parser(unparsed_args):
action = "store_true", action = "store_true",
default = False default = False
) )
group.add_option("-t", "--timeout",
dest = "timeout",
type = "int",
help = "Timeout to wait for the ESP8266 to accept invitation",
default = 10
)
parser.add_option_group(group) parser.add_option_group(group)
(options, args) = parser.parse_args(unparsed_args) (options, args) = parser.parse_args(unparsed_args)
@ -312,6 +325,10 @@ def main(args):
# check options # check options
global PROGRESS global PROGRESS
PROGRESS = options.progress PROGRESS = options.progress
global TIMEOUT
TIMEOUT = options.timeout
if (not options.esp_ip or not options.image): if (not options.esp_ip or not options.image):
logging.critical("Not enough arguments.") logging.critical("Not enough arguments.")
return 1 return 1