Skip to content

[OTA] Add UserSelectable timeout for invitation to device #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions tools/espota.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
sock2.close()
logging.error('Host %s Not Found', remoteAddr)
return 1
sock2.settimeout(1)
sock2.settimeout(TIMEOUT)
try:
data = sock2.recv(37).decode()
break;
Expand Down Expand Up @@ -162,7 +162,6 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
logging.error('No response from device')
sock.close()
return 1

try:
f = open(filename, "rb")
if (PROGRESS):
Expand Down Expand Up @@ -191,18 +190,26 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
sys.stderr.write('\n')
logging.info('Waiting for result...')
try:
connection.settimeout(60)
data = connection.recv(32).decode()
logging.info('Result: %s' ,data)
connection.close()
f.close()
sock.close()
if (data != "OK"):
sys.stderr.write('\n')
logging.error('%s', data)
return 1;
return 0
except:
count = 0
while True:
count=count+1
connection.settimeout(60)
data = connection.recv(32).decode()
logging.info('Result: %s' ,data)

if data == "OK":
logging.info('Success')
connection.close()
f.close()
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!')
connection.close()
f.close()
Expand Down Expand Up @@ -292,6 +299,12 @@ def parser(unparsed_args):
action = "store_true",
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)

(options, args) = parser.parse_args(unparsed_args)
Expand All @@ -312,6 +325,10 @@ def main(args):
# check options
global PROGRESS
PROGRESS = options.progress

global TIMEOUT
TIMEOUT = options.timeout

if (not options.esp_ip or not options.image):
logging.critical("Not enough arguments.")
return 1
Expand Down