[OTA] Add UserSelectable timeout for invitation to device + check for OK result in the last few messages (#1445)
This commit is contained in:
parent
03808e3b8b
commit
7b243adcfd
@ -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:
|
||||||
|
count = 0
|
||||||
|
while True:
|
||||||
|
count=count+1
|
||||||
connection.settimeout(60)
|
connection.settimeout(60)
|
||||||
data = connection.recv(32).decode()
|
data = connection.recv(32).decode()
|
||||||
logging.info('Result: %s' ,data)
|
logging.info('Result: %s' ,data)
|
||||||
|
|
||||||
|
if data == "OK":
|
||||||
|
logging.info('Success')
|
||||||
connection.close()
|
connection.close()
|
||||||
f.close()
|
f.close()
|
||||||
sock.close()
|
sock.close()
|
||||||
if (data != "OK"):
|
return 0;
|
||||||
sys.stderr.write('\n')
|
if count == 5:
|
||||||
logging.error('%s', data)
|
logging.error('Error response from device')
|
||||||
return 1;
|
connection.close()
|
||||||
return 0
|
f.close()
|
||||||
except:
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user