From ae586deeebaf852f3c28d3a2a7638b78756c41bd Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 25 Jun 2020 15:43:42 +1000 Subject: [PATCH] ci provisioning: Use strings instead of "magic numbers" for connection state --- examples/provisioning/legacy/ble_prov/ble_prov_test.py | 4 ++-- .../provisioning/legacy/softap_prov/softap_prov_test.py | 4 ++-- examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py | 6 +++--- tools/esp_prov/esp_prov.py | 4 ++-- tools/esp_prov/prov/wifi_prov.py | 8 +++++++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/provisioning/legacy/ble_prov/ble_prov_test.py b/examples/provisioning/legacy/ble_prov/ble_prov_test.py index eef5e51feb..c25a763850 100644 --- a/examples/provisioning/legacy/ble_prov/ble_prov_test.py +++ b/examples/provisioning/legacy/ble_prov/ble_prov_test.py @@ -87,9 +87,9 @@ def test_examples_provisioning_ble(env, extra_data): time.sleep(5) print("Wi-Fi connection state") ret = esp_prov.get_wifi_config(transport, security) - if (ret == 1): + if (ret == "connecting"): continue - elif (ret == 0): + elif (ret == "connected"): print("Provisioning was successful") success = True break diff --git a/examples/provisioning/legacy/softap_prov/softap_prov_test.py b/examples/provisioning/legacy/softap_prov/softap_prov_test.py index 7e1122a0b2..e4df4b4fc2 100644 --- a/examples/provisioning/legacy/softap_prov/softap_prov_test.py +++ b/examples/provisioning/legacy/softap_prov/softap_prov_test.py @@ -101,9 +101,9 @@ def test_examples_provisioning_softap(env, extra_data): time.sleep(5) print("Wi-Fi connection state") ret = esp_prov.get_wifi_config(transport, security) - if (ret == 1): + if (ret == "connecting"): continue - elif (ret == 0): + elif (ret == "connected"): print("Provisioning was successful") success = True break diff --git a/examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py b/examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py index aa00d75c58..14e400c574 100644 --- a/examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py +++ b/examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py @@ -96,12 +96,12 @@ def test_examples_wifi_prov_mgr(env, extra_data): time.sleep(5) print("Wi-Fi connection state") ret = esp_prov.get_wifi_config(transport, security) - if (ret == 1): + if (ret == "connecting"): continue - elif (ret == 0): + elif (ret == "connected"): print("Provisioning was successful") success = True - elif (ret == 3 and retry < 3): + elif (ret == "failed" and retry < 3): retry = retry + 1 print("Connection failed.. retry again...: ", ret) continue diff --git a/tools/esp_prov/esp_prov.py b/tools/esp_prov/esp_prov.py index 840f4c567d..04fd249fa9 100644 --- a/tools/esp_prov/esp_prov.py +++ b/tools/esp_prov/esp_prov.py @@ -475,9 +475,9 @@ if __name__ == '__main__': time.sleep(5) print("\n==== Wi-Fi connection state ====") ret = get_wifi_config(obj_transport, obj_security) - if (ret == 1): + if (ret == "connecting"): continue - elif (ret == 0): + elif (ret == "connected"): print("==== Provisioning was successful ====") else: print("---- Provisioning failed ----") diff --git a/tools/esp_prov/prov/wifi_prov.py b/tools/esp_prov/prov/wifi_prov.py index 9140291f96..11e4c0bde1 100644 --- a/tools/esp_prov/prov/wifi_prov.py +++ b/tools/esp_prov/prov/wifi_prov.py @@ -45,19 +45,25 @@ def config_get_status_response(security_ctx, response_data): cmd_resp1.ParseFromString(decrypted_message) print_verbose(security_ctx, "Response type " + str(cmd_resp1.msg)) print_verbose(security_ctx, "Response status " + str(cmd_resp1.resp_get_status.status)) + if cmd_resp1.resp_get_status.sta_state == 0: print("++++ WiFi state: " + "connected ++++") + return "connected" elif cmd_resp1.resp_get_status.sta_state == 1: print("++++ WiFi state: " + "connecting... ++++") + return "connecting" elif cmd_resp1.resp_get_status.sta_state == 2: print("++++ WiFi state: " + "disconnected ++++") + return "disconnected" elif cmd_resp1.resp_get_status.sta_state == 3: print("++++ WiFi state: " + "connection failed ++++") if cmd_resp1.resp_get_status.fail_reason == 0: print("++++ Failure reason: " + "Incorrect Password ++++") elif cmd_resp1.resp_get_status.fail_reason == 1: print("++++ Failure reason: " + "Incorrect SSID ++++") - return cmd_resp1.resp_get_status.sta_state + return "failed" + return "unknown" + def config_set_config_request(security_ctx, ssid, passphrase):