esp_prov: Refactor to use new 'wait_wifi_connected' function
Means all provisioning examples will have the same retry behaviour.
This commit is contained in:
parent
6787718e1b
commit
822b6986aa
5 changed files with 30 additions and 59 deletions
|
@ -17,7 +17,6 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
|
|
||||||
import ttfw_idf
|
import ttfw_idf
|
||||||
import esp_prov
|
import esp_prov
|
||||||
|
@ -82,19 +81,7 @@ def test_examples_provisioning_ble(env, extra_data):
|
||||||
if not esp_prov.apply_wifi_config(transport, security):
|
if not esp_prov.apply_wifi_config(transport, security):
|
||||||
raise RuntimeError("Failed to send apply config")
|
raise RuntimeError("Failed to send apply config")
|
||||||
|
|
||||||
success = False
|
if not esp_prov.wait_wifi_connected(transport, security):
|
||||||
while True:
|
|
||||||
time.sleep(5)
|
|
||||||
print("Wi-Fi connection state")
|
|
||||||
ret = esp_prov.get_wifi_config(transport, security)
|
|
||||||
if (ret == "connecting"):
|
|
||||||
continue
|
|
||||||
elif (ret == "connected"):
|
|
||||||
print("Provisioning was successful")
|
|
||||||
success = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not success:
|
|
||||||
raise RuntimeError("Provisioning failed")
|
raise RuntimeError("Provisioning failed")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
|
|
||||||
import ttfw_idf
|
import ttfw_idf
|
||||||
import esp_prov
|
import esp_prov
|
||||||
|
@ -86,24 +85,7 @@ def test_examples_wifi_prov_mgr(env, extra_data):
|
||||||
if not esp_prov.apply_wifi_config(transport, security):
|
if not esp_prov.apply_wifi_config(transport, security):
|
||||||
raise RuntimeError("Failed to send apply config")
|
raise RuntimeError("Failed to send apply config")
|
||||||
|
|
||||||
success = False
|
if not esp_prov.wait_wifi_connected(transport, security):
|
||||||
retry = 0
|
|
||||||
while True:
|
|
||||||
time.sleep(5)
|
|
||||||
print("Wi-Fi connection state")
|
|
||||||
ret = esp_prov.get_wifi_config(transport, security)
|
|
||||||
if (ret == "connecting"):
|
|
||||||
continue
|
|
||||||
elif (ret == "connected"):
|
|
||||||
print("Provisioning was successful")
|
|
||||||
success = True
|
|
||||||
elif (ret == "failed" and retry < 3):
|
|
||||||
retry = retry + 1
|
|
||||||
print("Connection failed.. retry again...: ", ret)
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
|
|
||||||
if not success:
|
|
||||||
raise RuntimeError("Provisioning failed")
|
raise RuntimeError("Provisioning failed")
|
||||||
|
|
||||||
# Check if BTDM memory is released after provisioning finishes
|
# Check if BTDM memory is released after provisioning finishes
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
|
|
||||||
import ttfw_idf
|
import ttfw_idf
|
||||||
import esp_prov
|
import esp_prov
|
||||||
|
@ -96,19 +95,7 @@ def test_examples_provisioning_softap(env, extra_data):
|
||||||
if not esp_prov.apply_wifi_config(transport, security):
|
if not esp_prov.apply_wifi_config(transport, security):
|
||||||
raise RuntimeError("Failed to send apply config")
|
raise RuntimeError("Failed to send apply config")
|
||||||
|
|
||||||
success = False
|
if not esp_prov.wait_wifi_connected(transport, security):
|
||||||
while True:
|
|
||||||
time.sleep(5)
|
|
||||||
print("Wi-Fi connection state")
|
|
||||||
ret = esp_prov.get_wifi_config(transport, security)
|
|
||||||
if (ret == "connecting"):
|
|
||||||
continue
|
|
||||||
elif (ret == "connected"):
|
|
||||||
print("Provisioning was successful")
|
|
||||||
success = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not success:
|
|
||||||
raise RuntimeError("Provisioning failed")
|
raise RuntimeError("Provisioning failed")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -266,6 +266,32 @@ def get_wifi_config(tp, sec):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def wait_wifi_connected(tp, sec):
|
||||||
|
"""
|
||||||
|
Wait for provisioning to report Wi-Fi is connected
|
||||||
|
|
||||||
|
Returns True if Wi-Fi connection succeeded, False if connection consistently failed
|
||||||
|
"""
|
||||||
|
TIME_PER_POLL = 5
|
||||||
|
retry = 3
|
||||||
|
|
||||||
|
while True:
|
||||||
|
time.sleep(TIME_PER_POLL)
|
||||||
|
print("\n==== Wi-Fi connection state ====")
|
||||||
|
ret = get_wifi_config(tp, sec)
|
||||||
|
if ret == "connecting":
|
||||||
|
continue
|
||||||
|
elif ret == "connected":
|
||||||
|
print("==== Provisioning was successful ====")
|
||||||
|
return True
|
||||||
|
elif retry > 0:
|
||||||
|
retry -= 1
|
||||||
|
print("Waiting to poll status again (status %s, %d tries left)..." % (ret, retry))
|
||||||
|
else:
|
||||||
|
print("---- Provisioning failed ----")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def desc_format(*args):
|
def desc_format(*args):
|
||||||
desc = ''
|
desc = ''
|
||||||
for arg in args:
|
for arg in args:
|
||||||
|
@ -449,14 +475,4 @@ if __name__ == '__main__':
|
||||||
exit(7)
|
exit(7)
|
||||||
print("==== Apply config sent successfully ====")
|
print("==== Apply config sent successfully ====")
|
||||||
|
|
||||||
while True:
|
wait_wifi_connected(obj_transport, obj_security)
|
||||||
time.sleep(5)
|
|
||||||
print("\n==== Wi-Fi connection state ====")
|
|
||||||
ret = get_wifi_config(obj_transport, obj_security)
|
|
||||||
if (ret == "connecting"):
|
|
||||||
continue
|
|
||||||
elif (ret == "connected"):
|
|
||||||
print("==== Provisioning was successful ====")
|
|
||||||
else:
|
|
||||||
print("---- Provisioning failed ----")
|
|
||||||
break
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ def config_get_status_response(security_ctx, response_data):
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def config_set_config_request(security_ctx, ssid, passphrase):
|
def config_set_config_request(security_ctx, ssid, passphrase):
|
||||||
# Form protobuf request packet for SetConfig command
|
# Form protobuf request packet for SetConfig command
|
||||||
cmd = proto.wifi_config_pb2.WiFiConfigPayload()
|
cmd = proto.wifi_config_pb2.WiFiConfigPayload()
|
||||||
|
|
Loading…
Reference in a new issue