Skip to content

Commit 5bdecb3

Browse files
projectgusespressif-bot
authored andcommitted
esp_prov: Refactor to use new 'wait_wifi_connected' function
Means all provisioning examples will have the same retry behaviour.
1 parent e969a5e commit 5bdecb3

File tree

5 files changed

+30
-59
lines changed

5 files changed

+30
-59
lines changed

examples/provisioning/legacy/ble_prov/ble_prov_test.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import print_function
1818
import re
1919
import os
20-
import time
2120

2221
import ttfw_idf
2322
import esp_prov
@@ -82,19 +81,7 @@ def test_examples_provisioning_ble(env, extra_data):
8281
if not esp_prov.apply_wifi_config(transport, security):
8382
raise RuntimeError("Failed to send apply config")
8483

85-
success = False
86-
while True:
87-
time.sleep(5)
88-
print("Wi-Fi connection state")
89-
ret = esp_prov.get_wifi_config(transport, security)
90-
if (ret == "connecting"):
91-
continue
92-
elif (ret == "connected"):
93-
print("Provisioning was successful")
94-
success = True
95-
break
96-
97-
if not success:
84+
if not esp_prov.wait_wifi_connected(transport, security):
9885
raise RuntimeError("Provisioning failed")
9986

10087

examples/provisioning/legacy/softap_prov/softap_prov_test.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import print_function
1818
import re
1919
import os
20-
import time
2120

2221
import ttfw_idf
2322
import esp_prov
@@ -96,19 +95,7 @@ def test_examples_provisioning_softap(env, extra_data):
9695
if not esp_prov.apply_wifi_config(transport, security):
9796
raise RuntimeError("Failed to send apply config")
9897

99-
success = False
100-
while True:
101-
time.sleep(5)
102-
print("Wi-Fi connection state")
103-
ret = esp_prov.get_wifi_config(transport, security)
104-
if (ret == "connecting"):
105-
continue
106-
elif (ret == "connected"):
107-
print("Provisioning was successful")
108-
success = True
109-
break
110-
111-
if not success:
98+
if not esp_prov.wait_wifi_connected(transport, security):
11299
raise RuntimeError("Provisioning failed")
113100

114101

examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import print_function
1818
import re
1919
import os
20-
import time
2120

2221
import ttfw_idf
2322
import esp_prov
@@ -90,24 +89,7 @@ def test_examples_wifi_prov_mgr(env, extra_data):
9089
if not esp_prov.apply_wifi_config(transport, security):
9190
raise RuntimeError("Failed to send apply config")
9291

93-
success = False
94-
retry = 0
95-
while True:
96-
time.sleep(5)
97-
print("Wi-Fi connection state")
98-
ret = esp_prov.get_wifi_config(transport, security)
99-
if (ret == "connecting"):
100-
continue
101-
elif (ret == "connected"):
102-
print("Provisioning was successful")
103-
success = True
104-
elif (ret == "failed" and retry < 3):
105-
retry = retry + 1
106-
print("Connection failed.. retry again...: ", ret)
107-
continue
108-
break
109-
110-
if not success:
92+
if not esp_prov.wait_wifi_connected(transport, security):
11193
raise RuntimeError("Provisioning failed")
11294

11395
# Check if BTDM memory is released after provisioning finishes

tools/esp_prov/esp_prov.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,32 @@ def get_wifi_config(tp, sec):
276276
return None
277277

278278

279+
def wait_wifi_connected(tp, sec):
280+
"""
281+
Wait for provisioning to report Wi-Fi is connected
282+
283+
Returns True if Wi-Fi connection succeeded, False if connection consistently failed
284+
"""
285+
TIME_PER_POLL = 5
286+
retry = 3
287+
288+
while True:
289+
time.sleep(TIME_PER_POLL)
290+
print("\n==== Wi-Fi connection state ====")
291+
ret = get_wifi_config(tp, sec)
292+
if ret == "connecting":
293+
continue
294+
elif ret == "connected":
295+
print("==== Provisioning was successful ====")
296+
return True
297+
elif retry > 0:
298+
retry -= 1
299+
print("Waiting to poll status again (status %s, %d tries left)..." % (ret, retry))
300+
else:
301+
print("---- Provisioning failed ----")
302+
return False
303+
304+
279305
def desc_format(*args):
280306
desc = ''
281307
for arg in args:
@@ -471,14 +497,4 @@ def desc_format(*args):
471497
exit(7)
472498
print("==== Apply config sent successfully ====")
473499

474-
while True:
475-
time.sleep(5)
476-
print("\n==== Wi-Fi connection state ====")
477-
ret = get_wifi_config(obj_transport, obj_security)
478-
if (ret == "connecting"):
479-
continue
480-
elif (ret == "connected"):
481-
print("==== Provisioning was successful ====")
482-
else:
483-
print("---- Provisioning failed ----")
484-
break
500+
wait_wifi_connected(obj_transport, obj_security)

tools/esp_prov/prov/wifi_prov.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def config_get_status_response(security_ctx, response_data):
6565
return "unknown"
6666

6767

68-
6968
def config_set_config_request(security_ctx, ssid, passphrase):
7069
# Form protobuf request packet for SetConfig command
7170
cmd = proto.wifi_config_pb2.WiFiConfigPayload()

0 commit comments

Comments
 (0)