From 156ae68275eb984d991302beb5624aec15818c7b Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Fri, 3 Jan 2020 20:57:49 +0530 Subject: [PATCH 1/3] provisioning_examples: Move older examples to legacy/ folder Change the manager example folder name to wifi_prov_mgr to sound more meaningful. Signed-off-by: Piyush Shah --- .flake8 | 2 +- .../api-reference/provisioning/protocomm.rst | 4 +-- .../provisioning/provisioning.rst | 12 ++++++--- .../provisioning/wifi_provisioning.rst | 20 +++++++++++++- examples/provisioning/README.md | 27 ++++++++++++++----- .../{ => legacy}/ble_prov/CMakeLists.txt | 0 .../{ => legacy}/ble_prov/Makefile | 0 .../{ => legacy}/ble_prov/README.md | 4 ++- .../{ => legacy}/ble_prov/ble_prov_test.py | 2 +- .../{ => legacy}/ble_prov/main/CMakeLists.txt | 0 .../ble_prov/main/Kconfig.projbuild | 0 .../{ => legacy}/ble_prov/main/app_main.c | 0 .../{ => legacy}/ble_prov/main/app_prov.c | 0 .../{ => legacy}/ble_prov/main/app_prov.h | 0 .../ble_prov/main/app_prov_handlers.c | 0 .../{ => legacy}/ble_prov/main/component.mk | 0 .../{ => legacy}/ble_prov/partitions.csv | 0 .../{ => legacy}/ble_prov/sdkconfig.defaults | 0 .../{ => legacy}/console_prov/CMakeLists.txt | 0 .../{ => legacy}/console_prov/Makefile | 0 .../{ => legacy}/console_prov/README.md | 4 ++- .../console_prov/main/CMakeLists.txt | 0 .../console_prov/main/Kconfig.projbuild | 0 .../{ => legacy}/console_prov/main/app_main.c | 0 .../{ => legacy}/console_prov/main/app_prov.c | 0 .../{ => legacy}/console_prov/main/app_prov.h | 0 .../console_prov/main/app_prov_handlers.c | 0 .../console_prov/main/component.mk | 0 .../{ => legacy}/custom_config/CMakeLists.txt | 0 .../{ => legacy}/custom_config/Makefile | 0 .../{ => legacy}/custom_config/README.md | 4 ++- .../custom_provisioning/CMakeLists.txt | 0 .../custom_provisioning/component.mk | 0 .../custom_provisioning/custom_config.h | 0 .../proto-c/custom_config.pb-c.c | 0 .../proto-c/custom_config.pb-c.h | 0 .../custom_provisioning/proto/CMakeLists.txt | 0 .../custom_provisioning/proto/README.md | 0 .../proto/custom_config.proto | 0 .../custom_provisioning/proto/makefile | 0 .../python/custom_config_pb2.py | 0 .../custom_provisioning/src/custom_config.c | 0 .../custom_config/main/CMakeLists.txt | 0 .../custom_config/main/Kconfig.projbuild | 0 .../custom_config/main/app_main.c | 0 .../custom_config/main/app_prov.c | 0 .../custom_config/main/app_prov.h | 0 .../custom_config/main/app_prov_handlers.c | 0 .../custom_config/main/component.mk | 0 .../{ => legacy}/softap_prov/CMakeLists.txt | 0 .../{ => legacy}/softap_prov/Makefile | 0 .../{ => legacy}/softap_prov/README.md | 4 ++- .../softap_prov/main/CMakeLists.txt | 0 .../softap_prov/main/Kconfig.projbuild | 0 .../{ => legacy}/softap_prov/main/app_main.c | 0 .../{ => legacy}/softap_prov/main/app_prov.c | 0 .../{ => legacy}/softap_prov/main/app_prov.h | 0 .../softap_prov/main/app_prov_handlers.c | 0 .../softap_prov}/main/component.mk | 0 .../softap_prov/softap_prov_test.py | 2 +- .../{manager => wifi_prov_mgr}/CMakeLists.txt | 0 .../{manager => wifi_prov_mgr}/Makefile | 0 .../{manager => wifi_prov_mgr}/README.md | 0 .../main/CMakeLists.txt | 0 .../main/app_main.c | 0 .../main/component.mk | 0 .../{manager => wifi_prov_mgr}/partitions.csv | 0 .../sdkconfig.defaults | 0 .../wifi_prov_mgr_test.py | 0 tools/esp_prov/proto/__init__.py | 2 +- 70 files changed, 66 insertions(+), 21 deletions(-) rename examples/provisioning/{ => legacy}/ble_prov/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/ble_prov/Makefile (100%) rename examples/provisioning/{ => legacy}/ble_prov/README.md (96%) rename examples/provisioning/{ => legacy}/ble_prov/ble_prov_test.py (96%) rename examples/provisioning/{ => legacy}/ble_prov/main/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/ble_prov/main/Kconfig.projbuild (100%) rename examples/provisioning/{ => legacy}/ble_prov/main/app_main.c (100%) rename examples/provisioning/{ => legacy}/ble_prov/main/app_prov.c (100%) rename examples/provisioning/{ => legacy}/ble_prov/main/app_prov.h (100%) rename examples/provisioning/{ => legacy}/ble_prov/main/app_prov_handlers.c (100%) rename examples/provisioning/{ => legacy}/ble_prov/main/component.mk (100%) rename examples/provisioning/{ => legacy}/ble_prov/partitions.csv (100%) rename examples/provisioning/{ => legacy}/ble_prov/sdkconfig.defaults (100%) rename examples/provisioning/{ => legacy}/console_prov/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/console_prov/Makefile (100%) rename examples/provisioning/{ => legacy}/console_prov/README.md (96%) rename examples/provisioning/{ => legacy}/console_prov/main/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/console_prov/main/Kconfig.projbuild (100%) rename examples/provisioning/{ => legacy}/console_prov/main/app_main.c (100%) rename examples/provisioning/{ => legacy}/console_prov/main/app_prov.c (100%) rename examples/provisioning/{ => legacy}/console_prov/main/app_prov.h (100%) rename examples/provisioning/{ => legacy}/console_prov/main/app_prov_handlers.c (100%) rename examples/provisioning/{ => legacy}/console_prov/main/component.mk (100%) rename examples/provisioning/{ => legacy}/custom_config/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/custom_config/Makefile (100%) rename examples/provisioning/{ => legacy}/custom_config/README.md (95%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/component.mk (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/include/custom_provisioning/custom_config.h (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.c (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.h (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/proto/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/proto/README.md (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/proto/custom_config.proto (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/proto/makefile (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/python/custom_config_pb2.py (100%) rename examples/provisioning/{ => legacy}/custom_config/components/custom_provisioning/src/custom_config.c (100%) rename examples/provisioning/{ => legacy}/custom_config/main/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/custom_config/main/Kconfig.projbuild (100%) rename examples/provisioning/{ => legacy}/custom_config/main/app_main.c (100%) rename examples/provisioning/{ => legacy}/custom_config/main/app_prov.c (100%) rename examples/provisioning/{ => legacy}/custom_config/main/app_prov.h (100%) rename examples/provisioning/{ => legacy}/custom_config/main/app_prov_handlers.c (100%) rename examples/provisioning/{ => legacy}/custom_config/main/component.mk (100%) rename examples/provisioning/{ => legacy}/softap_prov/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/softap_prov/Makefile (100%) rename examples/provisioning/{ => legacy}/softap_prov/README.md (95%) rename examples/provisioning/{ => legacy}/softap_prov/main/CMakeLists.txt (100%) rename examples/provisioning/{ => legacy}/softap_prov/main/Kconfig.projbuild (100%) rename examples/provisioning/{ => legacy}/softap_prov/main/app_main.c (100%) rename examples/provisioning/{ => legacy}/softap_prov/main/app_prov.c (100%) rename examples/provisioning/{ => legacy}/softap_prov/main/app_prov.h (100%) rename examples/provisioning/{ => legacy}/softap_prov/main/app_prov_handlers.c (100%) rename examples/provisioning/{manager => legacy/softap_prov}/main/component.mk (100%) rename examples/provisioning/{ => legacy}/softap_prov/softap_prov_test.py (97%) rename examples/provisioning/{manager => wifi_prov_mgr}/CMakeLists.txt (100%) rename examples/provisioning/{manager => wifi_prov_mgr}/Makefile (100%) rename examples/provisioning/{manager => wifi_prov_mgr}/README.md (100%) rename examples/provisioning/{manager => wifi_prov_mgr}/main/CMakeLists.txt (100%) rename examples/provisioning/{manager => wifi_prov_mgr}/main/app_main.c (100%) rename examples/provisioning/{softap_prov => wifi_prov_mgr}/main/component.mk (100%) rename examples/provisioning/{manager => wifi_prov_mgr}/partitions.csv (100%) rename examples/provisioning/{manager => wifi_prov_mgr}/sdkconfig.defaults (100%) rename examples/provisioning/{manager => wifi_prov_mgr}/wifi_prov_mgr_test.py (100%) diff --git a/.flake8 b/.flake8 index d3591e051..e98aa15f2 100644 --- a/.flake8 +++ b/.flake8 @@ -162,4 +162,4 @@ exclude = components/wifi_provisioning/python/wifi_config_pb2.py, components/wifi_provisioning/python/wifi_constants_pb2.py, components/esp_local_ctrl/python/esp_local_ctrl_pb2.py, - examples/provisioning/custom_config/components/custom_provisioning/python/custom_config_pb2.py, + examples/provisioning/legacy/custom_config/components/custom_provisioning/python/custom_config_pb2.py, diff --git a/docs/en/api-reference/provisioning/protocomm.rst b/docs/en/api-reference/provisioning/protocomm.rst index a8139d36a..02e20b86a 100644 --- a/docs/en/api-reference/provisioning/protocomm.rst +++ b/docs/en/api-reference/provisioning/protocomm.rst @@ -19,7 +19,7 @@ Note that the client still needs to establish session (only for protocomm_securi Transport Example (SoftAP + HTTP) with Security 1 ------------------------------------------------- -For complete example see :example:`provisioning/softap_prov` +For complete example see :example:`provisioning/legacy/softap_prov` .. highlight:: c @@ -113,7 +113,7 @@ For complete example see :example:`provisioning/softap_prov` Transport Example (BLE) with Security 0 --------------------------------------- -For complete example see :example:`provisioning/ble_prov` +For complete example see :example:`provisioning/legacy/ble_prov` .. highlight:: c diff --git a/docs/en/api-reference/provisioning/provisioning.rst b/docs/en/api-reference/provisioning/provisioning.rst index 40b7d21d7..97e1d3ea6 100644 --- a/docs/en/api-reference/provisioning/provisioning.rst +++ b/docs/en/api-reference/provisioning/provisioning.rst @@ -144,15 +144,21 @@ Sample Code >>>>>>>>>>> Please refer to :doc:`protocomm` and :doc:`wifi_provisioning` for API guides and code snippets on example usage. -Various use case implementations can be found as examples under :example:`provisioning`. +Application implementation can be found as an example under :example:`provisioning`. Provisioning Tools >>>>>>>>>>>>>>>>>> Provisioning applications are available for various platforms, along with source code: -* Android : `esp-idf-provisioning-android `_ -* iOS : `esp-idf-provisioning-ios `_ +* Android: + * `BLE Provisioning app on Play Store `_. + * `SoftAP Provisioning app on Play Store `_. + * Source code on GitHub: `esp-idf-provisioning-android `_. +* iOS: + * `BLE Provisioning app on app store `_. + * `SoftAP Provisioning app on app Store `_. + * Source code on GitHub: `esp-idf-provisioning-ios `_. * Linux/MacOS/Windows : :idf:`tools/esp_prov` (a python based command line tool for provisioning) The phone applications offer simple UI and thus more user centric, while the command line application is useful as a debugging tool for developers. diff --git a/docs/en/api-reference/provisioning/wifi_provisioning.rst b/docs/en/api-reference/provisioning/wifi_provisioning.rst index 06c33ef1d..7e89516d1 100644 --- a/docs/en/api-reference/provisioning/wifi_provisioning.rst +++ b/docs/en/api-reference/provisioning/wifi_provisioning.rst @@ -274,7 +274,25 @@ The customized behavior is useful for applications which want the provisioning s Application Examples -------------------- -For complete example implementation see :example:`provisioning/manager` +For complete example implementation see :example:`provisioning/wifi_prov_mgr` + +Provisioning Tools +-------------------- + +Provisioning applications are available for various platforms, along with source code: + +* Android: + * `BLE Provisioning app on Play Store `_. + * `SoftAP Provisioning app on Play Store `_. + * Source code on GitHub: `esp-idf-provisioning-android `_. +* iOS: + * `BLE Provisioning app on app store `_. + * `SoftAP Provisioning app on app Store `_. + * Source code on GitHub: `esp-idf-provisioning-ios `_. +* Linux/MacOS/Windows : :idf:`tools/esp_prov` (a python based command line tool for provisioning) + +The phone applications offer simple UI and thus more user centric, while the command line application is useful as a debugging tool for developers. + API Reference ------------- diff --git a/examples/provisioning/README.md b/examples/provisioning/README.md index 96e0b93bb..98134d411 100644 --- a/examples/provisioning/README.md +++ b/examples/provisioning/README.md @@ -1,6 +1,25 @@ # Provisioning Application Examples -These consist of the following examples : +This primarily consists of a single unified example wifi_prov_mgr + +* wifi_prov_mgr + Abstracts out most of the complexity of Wi-Fi provisioning and allows easy switching between the SoftAP (using HTTP) and BLE transports. + +Provisioning applications are available for various platforms: + +* Android: + - [BLE Provisioning app on Play Store](https://play.google.com/store/apps/details?id=com.espressif.provble). + - [SoftAP Provisioning app on Play Store](https://play.google.com/store/apps/details?id=com.espressif.provsoftap). + - Source code on GitHub: [esp-idf-provisioning-android](https://github.com/espressif/esp-idf-provisioning-android). +* iOS: + - [BLE Provisioning app on app store](https://apps.apple.com/in/app/esp-ble-provisioning/id1473590141) + - [SoftAP Provisioning app on app Store](https://apps.apple.com/in/app/esp-softap-provisioning/id1474040630) + - Source code on GitHub: [esp-idf-provisioning-ios](https://github.com/espressif/esp-idf-provisioning-ios) +* For all other platforms a python based command line tool is provided under "$IDF_PATH/tools/esp_prov" + +## Legacy Examples + +The legacy examples require own implementation of provisioning functions and handlers. The Wi-Fi provisioning component abstracts out most of this complexity and provides a simpler interface and so, that is recommended for use. However, if you want to use lower level provisioning and protocomm APIs, you can check the these examples under legacy/ folder: * softap_prov Provisioning involves Wi-Fi station configuration via an HTTP server running on the device, which is initially configured to be in SoftAP mode. After provisioning, device runs in Wi-Fi station mode only and connects to the AP whose credentials were provided during provisioning. @@ -14,10 +33,4 @@ These consist of the following examples : * custom_config Similar to softap_prov examples, but allows for configuration of custom (device-local) information during provisioning. This is intended as an example for implementing custom provisioning schemes. -Provisioning applications are available for various platforms: - -* For Android, a provisioning application along with source code is available on GitHub : [esp-idf-provisioning-android](https://github.com/espressif/esp-idf-provisioning-android) -* For iOS, a provisioning application along with source code is available on GitHub : [esp-idf-provisioning-ios](https://github.com/espressif/esp-idf-provisioning-ios) -* For all other platforms a python based command line tool is provided under "$IDF_PATH/tools/esp_prov" - Refer to the README.md files in each example directory for more information. diff --git a/examples/provisioning/ble_prov/CMakeLists.txt b/examples/provisioning/legacy/ble_prov/CMakeLists.txt similarity index 100% rename from examples/provisioning/ble_prov/CMakeLists.txt rename to examples/provisioning/legacy/ble_prov/CMakeLists.txt diff --git a/examples/provisioning/ble_prov/Makefile b/examples/provisioning/legacy/ble_prov/Makefile similarity index 100% rename from examples/provisioning/ble_prov/Makefile rename to examples/provisioning/legacy/ble_prov/Makefile diff --git a/examples/provisioning/ble_prov/README.md b/examples/provisioning/legacy/ble_prov/README.md similarity index 96% rename from examples/provisioning/ble_prov/README.md rename to examples/provisioning/legacy/ble_prov/README.md index 1c871e657..949035aaf 100644 --- a/examples/provisioning/ble_prov/README.md +++ b/examples/provisioning/legacy/ble_prov/README.md @@ -1,4 +1,6 @@ -# BLE based Provisioning Example +# BLE based Provisioning Example (Legacy) + +> Note: It is recommended to use the new `wifi_prov_mgr` example which is based on the simpler `wifi_provisioning` APIs. Check this example only if you wish to use lower level provisioning and protocomm APIs and want more control over the handlers. (See the README.md file in the upper level 'examples' directory for more information about examples.) diff --git a/examples/provisioning/ble_prov/ble_prov_test.py b/examples/provisioning/legacy/ble_prov/ble_prov_test.py similarity index 96% rename from examples/provisioning/ble_prov/ble_prov_test.py rename to examples/provisioning/legacy/ble_prov/ble_prov_test.py index c4f57780c..eef5e51fe 100644 --- a/examples/provisioning/ble_prov/ble_prov_test.py +++ b/examples/provisioning/legacy/ble_prov/ble_prov_test.py @@ -29,7 +29,7 @@ esp_prov.config_throw_except = True @ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT") def test_examples_provisioning_ble(env, extra_data): # Acquire DUT - dut1 = env.get_dut("ble_prov", "examples/provisioning/ble_prov", dut_class=ttfw_idf.ESP32DUT) + dut1 = env.get_dut("ble_prov", "examples/provisioning/legacy/ble_prov", dut_class=ttfw_idf.ESP32DUT) # Get binary file binary_file = os.path.join(dut1.app.binary_path, "ble_prov.bin") diff --git a/examples/provisioning/ble_prov/main/CMakeLists.txt b/examples/provisioning/legacy/ble_prov/main/CMakeLists.txt similarity index 100% rename from examples/provisioning/ble_prov/main/CMakeLists.txt rename to examples/provisioning/legacy/ble_prov/main/CMakeLists.txt diff --git a/examples/provisioning/ble_prov/main/Kconfig.projbuild b/examples/provisioning/legacy/ble_prov/main/Kconfig.projbuild similarity index 100% rename from examples/provisioning/ble_prov/main/Kconfig.projbuild rename to examples/provisioning/legacy/ble_prov/main/Kconfig.projbuild diff --git a/examples/provisioning/ble_prov/main/app_main.c b/examples/provisioning/legacy/ble_prov/main/app_main.c similarity index 100% rename from examples/provisioning/ble_prov/main/app_main.c rename to examples/provisioning/legacy/ble_prov/main/app_main.c diff --git a/examples/provisioning/ble_prov/main/app_prov.c b/examples/provisioning/legacy/ble_prov/main/app_prov.c similarity index 100% rename from examples/provisioning/ble_prov/main/app_prov.c rename to examples/provisioning/legacy/ble_prov/main/app_prov.c diff --git a/examples/provisioning/ble_prov/main/app_prov.h b/examples/provisioning/legacy/ble_prov/main/app_prov.h similarity index 100% rename from examples/provisioning/ble_prov/main/app_prov.h rename to examples/provisioning/legacy/ble_prov/main/app_prov.h diff --git a/examples/provisioning/ble_prov/main/app_prov_handlers.c b/examples/provisioning/legacy/ble_prov/main/app_prov_handlers.c similarity index 100% rename from examples/provisioning/ble_prov/main/app_prov_handlers.c rename to examples/provisioning/legacy/ble_prov/main/app_prov_handlers.c diff --git a/examples/provisioning/ble_prov/main/component.mk b/examples/provisioning/legacy/ble_prov/main/component.mk similarity index 100% rename from examples/provisioning/ble_prov/main/component.mk rename to examples/provisioning/legacy/ble_prov/main/component.mk diff --git a/examples/provisioning/ble_prov/partitions.csv b/examples/provisioning/legacy/ble_prov/partitions.csv similarity index 100% rename from examples/provisioning/ble_prov/partitions.csv rename to examples/provisioning/legacy/ble_prov/partitions.csv diff --git a/examples/provisioning/ble_prov/sdkconfig.defaults b/examples/provisioning/legacy/ble_prov/sdkconfig.defaults similarity index 100% rename from examples/provisioning/ble_prov/sdkconfig.defaults rename to examples/provisioning/legacy/ble_prov/sdkconfig.defaults diff --git a/examples/provisioning/console_prov/CMakeLists.txt b/examples/provisioning/legacy/console_prov/CMakeLists.txt similarity index 100% rename from examples/provisioning/console_prov/CMakeLists.txt rename to examples/provisioning/legacy/console_prov/CMakeLists.txt diff --git a/examples/provisioning/console_prov/Makefile b/examples/provisioning/legacy/console_prov/Makefile similarity index 100% rename from examples/provisioning/console_prov/Makefile rename to examples/provisioning/legacy/console_prov/Makefile diff --git a/examples/provisioning/console_prov/README.md b/examples/provisioning/legacy/console_prov/README.md similarity index 96% rename from examples/provisioning/console_prov/README.md rename to examples/provisioning/legacy/console_prov/README.md index 685fdf66c..9965bb25b 100644 --- a/examples/provisioning/console_prov/README.md +++ b/examples/provisioning/legacy/console_prov/README.md @@ -1,4 +1,6 @@ -# Console based Provisioning Example +# Console based Provisioning Example (Legacy) + +> Check this example only if you wish to use console based provisioning. For any real applications, it is recommended to use the new `wifi_prov_mgr` example which is based on the simpler `wifi_provisioning` APIs. (See the README.md file in the upper level 'examples' directory for more information about examples.) diff --git a/examples/provisioning/console_prov/main/CMakeLists.txt b/examples/provisioning/legacy/console_prov/main/CMakeLists.txt similarity index 100% rename from examples/provisioning/console_prov/main/CMakeLists.txt rename to examples/provisioning/legacy/console_prov/main/CMakeLists.txt diff --git a/examples/provisioning/console_prov/main/Kconfig.projbuild b/examples/provisioning/legacy/console_prov/main/Kconfig.projbuild similarity index 100% rename from examples/provisioning/console_prov/main/Kconfig.projbuild rename to examples/provisioning/legacy/console_prov/main/Kconfig.projbuild diff --git a/examples/provisioning/console_prov/main/app_main.c b/examples/provisioning/legacy/console_prov/main/app_main.c similarity index 100% rename from examples/provisioning/console_prov/main/app_main.c rename to examples/provisioning/legacy/console_prov/main/app_main.c diff --git a/examples/provisioning/console_prov/main/app_prov.c b/examples/provisioning/legacy/console_prov/main/app_prov.c similarity index 100% rename from examples/provisioning/console_prov/main/app_prov.c rename to examples/provisioning/legacy/console_prov/main/app_prov.c diff --git a/examples/provisioning/console_prov/main/app_prov.h b/examples/provisioning/legacy/console_prov/main/app_prov.h similarity index 100% rename from examples/provisioning/console_prov/main/app_prov.h rename to examples/provisioning/legacy/console_prov/main/app_prov.h diff --git a/examples/provisioning/console_prov/main/app_prov_handlers.c b/examples/provisioning/legacy/console_prov/main/app_prov_handlers.c similarity index 100% rename from examples/provisioning/console_prov/main/app_prov_handlers.c rename to examples/provisioning/legacy/console_prov/main/app_prov_handlers.c diff --git a/examples/provisioning/console_prov/main/component.mk b/examples/provisioning/legacy/console_prov/main/component.mk similarity index 100% rename from examples/provisioning/console_prov/main/component.mk rename to examples/provisioning/legacy/console_prov/main/component.mk diff --git a/examples/provisioning/custom_config/CMakeLists.txt b/examples/provisioning/legacy/custom_config/CMakeLists.txt similarity index 100% rename from examples/provisioning/custom_config/CMakeLists.txt rename to examples/provisioning/legacy/custom_config/CMakeLists.txt diff --git a/examples/provisioning/custom_config/Makefile b/examples/provisioning/legacy/custom_config/Makefile similarity index 100% rename from examples/provisioning/custom_config/Makefile rename to examples/provisioning/legacy/custom_config/Makefile diff --git a/examples/provisioning/custom_config/README.md b/examples/provisioning/legacy/custom_config/README.md similarity index 95% rename from examples/provisioning/custom_config/README.md rename to examples/provisioning/legacy/custom_config/README.md index dba1854a6..8cf9eea9e 100644 --- a/examples/provisioning/custom_config/README.md +++ b/examples/provisioning/legacy/custom_config/README.md @@ -1,4 +1,6 @@ -# SoftAP + HTTPD based Provisioning Example featuring Custom configuration +# SoftAP + HTTPD based Provisioning Example featuring Custom configuration (Legacy) + +> Note: It is recommended to use the new `wifi_prov_mgr` example which is based on the simpler `wifi_provisioning` APIs. Check this example only if you wish to use lower level provisioning and protocomm APIs and want more control over the handlers. (See the README.md file in the upper level 'examples' directory for more information about examples.) diff --git a/examples/provisioning/custom_config/components/custom_provisioning/CMakeLists.txt b/examples/provisioning/legacy/custom_config/components/custom_provisioning/CMakeLists.txt similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/CMakeLists.txt rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/CMakeLists.txt diff --git a/examples/provisioning/custom_config/components/custom_provisioning/component.mk b/examples/provisioning/legacy/custom_config/components/custom_provisioning/component.mk similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/component.mk rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/component.mk diff --git a/examples/provisioning/custom_config/components/custom_provisioning/include/custom_provisioning/custom_config.h b/examples/provisioning/legacy/custom_config/components/custom_provisioning/include/custom_provisioning/custom_config.h similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/include/custom_provisioning/custom_config.h rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/include/custom_provisioning/custom_config.h diff --git a/examples/provisioning/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.c b/examples/provisioning/legacy/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.c similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.c rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.c diff --git a/examples/provisioning/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.h b/examples/provisioning/legacy/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.h similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.h rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/proto-c/custom_config.pb-c.h diff --git a/examples/provisioning/custom_config/components/custom_provisioning/proto/CMakeLists.txt b/examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/CMakeLists.txt similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/proto/CMakeLists.txt rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/CMakeLists.txt diff --git a/examples/provisioning/custom_config/components/custom_provisioning/proto/README.md b/examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/README.md similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/proto/README.md rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/README.md diff --git a/examples/provisioning/custom_config/components/custom_provisioning/proto/custom_config.proto b/examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/custom_config.proto similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/proto/custom_config.proto rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/custom_config.proto diff --git a/examples/provisioning/custom_config/components/custom_provisioning/proto/makefile b/examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/makefile similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/proto/makefile rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/proto/makefile diff --git a/examples/provisioning/custom_config/components/custom_provisioning/python/custom_config_pb2.py b/examples/provisioning/legacy/custom_config/components/custom_provisioning/python/custom_config_pb2.py similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/python/custom_config_pb2.py rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/python/custom_config_pb2.py diff --git a/examples/provisioning/custom_config/components/custom_provisioning/src/custom_config.c b/examples/provisioning/legacy/custom_config/components/custom_provisioning/src/custom_config.c similarity index 100% rename from examples/provisioning/custom_config/components/custom_provisioning/src/custom_config.c rename to examples/provisioning/legacy/custom_config/components/custom_provisioning/src/custom_config.c diff --git a/examples/provisioning/custom_config/main/CMakeLists.txt b/examples/provisioning/legacy/custom_config/main/CMakeLists.txt similarity index 100% rename from examples/provisioning/custom_config/main/CMakeLists.txt rename to examples/provisioning/legacy/custom_config/main/CMakeLists.txt diff --git a/examples/provisioning/custom_config/main/Kconfig.projbuild b/examples/provisioning/legacy/custom_config/main/Kconfig.projbuild similarity index 100% rename from examples/provisioning/custom_config/main/Kconfig.projbuild rename to examples/provisioning/legacy/custom_config/main/Kconfig.projbuild diff --git a/examples/provisioning/custom_config/main/app_main.c b/examples/provisioning/legacy/custom_config/main/app_main.c similarity index 100% rename from examples/provisioning/custom_config/main/app_main.c rename to examples/provisioning/legacy/custom_config/main/app_main.c diff --git a/examples/provisioning/custom_config/main/app_prov.c b/examples/provisioning/legacy/custom_config/main/app_prov.c similarity index 100% rename from examples/provisioning/custom_config/main/app_prov.c rename to examples/provisioning/legacy/custom_config/main/app_prov.c diff --git a/examples/provisioning/custom_config/main/app_prov.h b/examples/provisioning/legacy/custom_config/main/app_prov.h similarity index 100% rename from examples/provisioning/custom_config/main/app_prov.h rename to examples/provisioning/legacy/custom_config/main/app_prov.h diff --git a/examples/provisioning/custom_config/main/app_prov_handlers.c b/examples/provisioning/legacy/custom_config/main/app_prov_handlers.c similarity index 100% rename from examples/provisioning/custom_config/main/app_prov_handlers.c rename to examples/provisioning/legacy/custom_config/main/app_prov_handlers.c diff --git a/examples/provisioning/custom_config/main/component.mk b/examples/provisioning/legacy/custom_config/main/component.mk similarity index 100% rename from examples/provisioning/custom_config/main/component.mk rename to examples/provisioning/legacy/custom_config/main/component.mk diff --git a/examples/provisioning/softap_prov/CMakeLists.txt b/examples/provisioning/legacy/softap_prov/CMakeLists.txt similarity index 100% rename from examples/provisioning/softap_prov/CMakeLists.txt rename to examples/provisioning/legacy/softap_prov/CMakeLists.txt diff --git a/examples/provisioning/softap_prov/Makefile b/examples/provisioning/legacy/softap_prov/Makefile similarity index 100% rename from examples/provisioning/softap_prov/Makefile rename to examples/provisioning/legacy/softap_prov/Makefile diff --git a/examples/provisioning/softap_prov/README.md b/examples/provisioning/legacy/softap_prov/README.md similarity index 95% rename from examples/provisioning/softap_prov/README.md rename to examples/provisioning/legacy/softap_prov/README.md index 086a18e63..750024904 100644 --- a/examples/provisioning/softap_prov/README.md +++ b/examples/provisioning/legacy/softap_prov/README.md @@ -1,4 +1,6 @@ -# SoftAP + HTTPD based Provisioning Example +# SoftAP + HTTPD based Provisioning Example (Legacy) + +> Note: It is recommended to use the new `wifi_prov_mgr` example which is based on the simpler `wifi_provisioning` APIs. Check this example only if you wish to use lower level provisioning and protocomm APIs and want more control over the handlers. (See the README.md file in the upper level 'examples' directory for more information about examples.) diff --git a/examples/provisioning/softap_prov/main/CMakeLists.txt b/examples/provisioning/legacy/softap_prov/main/CMakeLists.txt similarity index 100% rename from examples/provisioning/softap_prov/main/CMakeLists.txt rename to examples/provisioning/legacy/softap_prov/main/CMakeLists.txt diff --git a/examples/provisioning/softap_prov/main/Kconfig.projbuild b/examples/provisioning/legacy/softap_prov/main/Kconfig.projbuild similarity index 100% rename from examples/provisioning/softap_prov/main/Kconfig.projbuild rename to examples/provisioning/legacy/softap_prov/main/Kconfig.projbuild diff --git a/examples/provisioning/softap_prov/main/app_main.c b/examples/provisioning/legacy/softap_prov/main/app_main.c similarity index 100% rename from examples/provisioning/softap_prov/main/app_main.c rename to examples/provisioning/legacy/softap_prov/main/app_main.c diff --git a/examples/provisioning/softap_prov/main/app_prov.c b/examples/provisioning/legacy/softap_prov/main/app_prov.c similarity index 100% rename from examples/provisioning/softap_prov/main/app_prov.c rename to examples/provisioning/legacy/softap_prov/main/app_prov.c diff --git a/examples/provisioning/softap_prov/main/app_prov.h b/examples/provisioning/legacy/softap_prov/main/app_prov.h similarity index 100% rename from examples/provisioning/softap_prov/main/app_prov.h rename to examples/provisioning/legacy/softap_prov/main/app_prov.h diff --git a/examples/provisioning/softap_prov/main/app_prov_handlers.c b/examples/provisioning/legacy/softap_prov/main/app_prov_handlers.c similarity index 100% rename from examples/provisioning/softap_prov/main/app_prov_handlers.c rename to examples/provisioning/legacy/softap_prov/main/app_prov_handlers.c diff --git a/examples/provisioning/manager/main/component.mk b/examples/provisioning/legacy/softap_prov/main/component.mk similarity index 100% rename from examples/provisioning/manager/main/component.mk rename to examples/provisioning/legacy/softap_prov/main/component.mk diff --git a/examples/provisioning/softap_prov/softap_prov_test.py b/examples/provisioning/legacy/softap_prov/softap_prov_test.py similarity index 97% rename from examples/provisioning/softap_prov/softap_prov_test.py rename to examples/provisioning/legacy/softap_prov/softap_prov_test.py index 09381b362..238234c15 100644 --- a/examples/provisioning/softap_prov/softap_prov_test.py +++ b/examples/provisioning/legacy/softap_prov/softap_prov_test.py @@ -30,7 +30,7 @@ esp_prov.config_throw_except = True @ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT") def test_examples_provisioning_softap(env, extra_data): # Acquire DUT - dut1 = env.get_dut("softap_prov", "examples/provisioning/softap_prov", dut_class=ttfw_idf.ESP32DUT) + dut1 = env.get_dut("softap_prov", "examples/provisioning/legacy/softap_prov", dut_class=ttfw_idf.ESP32DUT) # Get binary file binary_file = os.path.join(dut1.app.binary_path, "softap_prov.bin") diff --git a/examples/provisioning/manager/CMakeLists.txt b/examples/provisioning/wifi_prov_mgr/CMakeLists.txt similarity index 100% rename from examples/provisioning/manager/CMakeLists.txt rename to examples/provisioning/wifi_prov_mgr/CMakeLists.txt diff --git a/examples/provisioning/manager/Makefile b/examples/provisioning/wifi_prov_mgr/Makefile similarity index 100% rename from examples/provisioning/manager/Makefile rename to examples/provisioning/wifi_prov_mgr/Makefile diff --git a/examples/provisioning/manager/README.md b/examples/provisioning/wifi_prov_mgr/README.md similarity index 100% rename from examples/provisioning/manager/README.md rename to examples/provisioning/wifi_prov_mgr/README.md diff --git a/examples/provisioning/manager/main/CMakeLists.txt b/examples/provisioning/wifi_prov_mgr/main/CMakeLists.txt similarity index 100% rename from examples/provisioning/manager/main/CMakeLists.txt rename to examples/provisioning/wifi_prov_mgr/main/CMakeLists.txt diff --git a/examples/provisioning/manager/main/app_main.c b/examples/provisioning/wifi_prov_mgr/main/app_main.c similarity index 100% rename from examples/provisioning/manager/main/app_main.c rename to examples/provisioning/wifi_prov_mgr/main/app_main.c diff --git a/examples/provisioning/softap_prov/main/component.mk b/examples/provisioning/wifi_prov_mgr/main/component.mk similarity index 100% rename from examples/provisioning/softap_prov/main/component.mk rename to examples/provisioning/wifi_prov_mgr/main/component.mk diff --git a/examples/provisioning/manager/partitions.csv b/examples/provisioning/wifi_prov_mgr/partitions.csv similarity index 100% rename from examples/provisioning/manager/partitions.csv rename to examples/provisioning/wifi_prov_mgr/partitions.csv diff --git a/examples/provisioning/manager/sdkconfig.defaults b/examples/provisioning/wifi_prov_mgr/sdkconfig.defaults similarity index 100% rename from examples/provisioning/manager/sdkconfig.defaults rename to examples/provisioning/wifi_prov_mgr/sdkconfig.defaults diff --git a/examples/provisioning/manager/wifi_prov_mgr_test.py b/examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py similarity index 100% rename from examples/provisioning/manager/wifi_prov_mgr_test.py rename to examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py diff --git a/tools/esp_prov/proto/__init__.py b/tools/esp_prov/proto/__init__.py index 82726cd95..54186629d 100644 --- a/tools/esp_prov/proto/__init__.py +++ b/tools/esp_prov/proto/__init__.py @@ -41,4 +41,4 @@ wifi_scan_pb2 = _load_source("wifi_scan_pb2", idf_path + "/components/ # custom_provisioning component related python files generated from .proto files custom_config_pb2 = _load_source("custom_config_pb2", idf_path + - "/examples/provisioning/custom_config/components/custom_provisioning/python/custom_config_pb2.py") + "/examples/provisioning/legacy/custom_config/components/custom_provisioning/python/custom_config_pb2.py") From 9ee5f3e8cea1ac64a5ea1471c918ba58d0d7433f Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Fri, 3 Jan 2020 21:06:10 +0530 Subject: [PATCH 2/3] wifi_prov_mgr: Add config options to switch transport and support for custom data Config options have been set such that BLE transport will be the default for ESP32 and SoftAP will be the default for ESP-S2. CMakeLists.txt for all provisioning examples applicable for ESP32-S2 have also been updated as these now work fine on ESP32-S2 Signed-off-by: Piyush Shah --- examples/provisioning/README.md | 2 +- .../legacy/console_prov/CMakeLists.txt | 1 - .../legacy/custom_config/CMakeLists.txt | 1 - .../legacy/softap_prov/CMakeLists.txt | 1 - .../provisioning/wifi_prov_mgr/CMakeLists.txt | 1 - examples/provisioning/wifi_prov_mgr/README.md | 28 ++++++++-- .../wifi_prov_mgr/main/Kconfig.projbuild | 22 ++++++++ .../wifi_prov_mgr/main/app_main.c | 54 +++++++++++++++++++ .../wifi_prov_mgr/wifi_prov_mgr_test.py | 6 ++- 9 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 examples/provisioning/wifi_prov_mgr/main/Kconfig.projbuild diff --git a/examples/provisioning/README.md b/examples/provisioning/README.md index 98134d411..4a755e3f5 100644 --- a/examples/provisioning/README.md +++ b/examples/provisioning/README.md @@ -3,7 +3,7 @@ This primarily consists of a single unified example wifi_prov_mgr * wifi_prov_mgr - Abstracts out most of the complexity of Wi-Fi provisioning and allows easy switching between the SoftAP (using HTTP) and BLE transports. + Abstracts out most of the complexity of Wi-Fi provisioning and allows easy switching between the SoftAP (using HTTP) and BLE transports. It also demonstrates how applications can register and use additional custom data endpoints. Provisioning applications are available for various platforms: diff --git a/examples/provisioning/legacy/console_prov/CMakeLists.txt b/examples/provisioning/legacy/console_prov/CMakeLists.txt index 5352f1e19..654200588 100644 --- a/examples/provisioning/legacy/console_prov/CMakeLists.txt +++ b/examples/provisioning/legacy/console_prov/CMakeLists.txt @@ -2,6 +2,5 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -set(SUPPORTED_TARGETS esp32) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(console_prov) diff --git a/examples/provisioning/legacy/custom_config/CMakeLists.txt b/examples/provisioning/legacy/custom_config/CMakeLists.txt index ca8359f82..ec9b0ce66 100644 --- a/examples/provisioning/legacy/custom_config/CMakeLists.txt +++ b/examples/provisioning/legacy/custom_config/CMakeLists.txt @@ -2,6 +2,5 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -set(SUPPORTED_TARGETS esp32) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(custom_config) diff --git a/examples/provisioning/legacy/softap_prov/CMakeLists.txt b/examples/provisioning/legacy/softap_prov/CMakeLists.txt index e63c8e4ed..fa6ac1433 100644 --- a/examples/provisioning/legacy/softap_prov/CMakeLists.txt +++ b/examples/provisioning/legacy/softap_prov/CMakeLists.txt @@ -2,6 +2,5 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -set(SUPPORTED_TARGETS esp32) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(softap_prov) diff --git a/examples/provisioning/wifi_prov_mgr/CMakeLists.txt b/examples/provisioning/wifi_prov_mgr/CMakeLists.txt index a628955d3..b036d9ce6 100644 --- a/examples/provisioning/wifi_prov_mgr/CMakeLists.txt +++ b/examples/provisioning/wifi_prov_mgr/CMakeLists.txt @@ -2,6 +2,5 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -set(SUPPORTED_TARGETS esp32) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(wifi_prov_mgr) diff --git a/examples/provisioning/wifi_prov_mgr/README.md b/examples/provisioning/wifi_prov_mgr/README.md index d514d7bde..e9c811248 100644 --- a/examples/provisioning/wifi_prov_mgr/README.md +++ b/examples/provisioning/wifi_prov_mgr/README.md @@ -4,7 +4,9 @@ `wifi_prov_mgr` example demonstrates the usage of `wifi_provisioning` manager component for building a provisioning application. -For this example BLE is chosen as the mode of transport, over which the provisioning related communication is to take place, between the device (to be provisioned) and the client (owner of the device). +For this example, BLE is chosen as the default mode of transport, over which the provisioning related communication is to take place. NimBLE has been configured as the default host, but you can also switch to Bluedroid using menuconfig -> Components -> Bluetooth -> Bluetooth Host. + +> Note: Since ESP32-S2 does not support BLE, the SoftAP will be the default mode of transport in that case. Even for ESP32, you can change to SoftAP transport from menuconfig. In the provisioning process the device is configured as a Wi-Fi station with specified credentials. Once configured, the device will retain the Wi-Fi configuration, until a flash erase is performed. @@ -22,7 +24,7 @@ This example can be used, as it is, for adding a provisioning service to any app ### Hardware Required -Example should be able to run on any commonly available ESP32 development board. +Example should be able to run on any commonly available ESP32/ESP32-S2 development board. ### Application Required @@ -49,7 +51,7 @@ There are various applications, specific to Windows and macOS platform which can ``` idf.py menuconfig ``` - +* Set the BLE/Soft AP transport under "Example Configuration" options. ESP32-S2 will have only SoftAP option. * Set serial port under Serial Flasher Options. ### Build and Flash @@ -157,6 +159,26 @@ Enter passphrase for MyHomeWiFiAP : ==== Provisioning was successful ==== ``` +### Sending Custom Data + +The provisioning manager allows applications to send some custom data during provisioning, which may be +required for some other operations like connecting to some cloud service. This is achieved by creating +and registering additional endpoints using the below APIs + +``` +wifi_prov_mgr_endpoint_create(); +wifi_prov_mgr_endpoint_register(); +``` + +In this particular example, we have added an endpoint named "custom-data" which can be tested +by passing the `--custom_data ` option to the esp\_prov tool. Following output is +expected on success: + +``` +==== Sending Custom data to esp32 ==== +CustomData response: SUCCESS +``` + ## Troubleshooting ### Provisioning failed diff --git a/examples/provisioning/wifi_prov_mgr/main/Kconfig.projbuild b/examples/provisioning/wifi_prov_mgr/main/Kconfig.projbuild new file mode 100644 index 000000000..3cd03d66b --- /dev/null +++ b/examples/provisioning/wifi_prov_mgr/main/Kconfig.projbuild @@ -0,0 +1,22 @@ +menu "Example Configuration" + + choice EXAMPLE_PROV_TRANSPORT + bool "Provisioning Transport" + default EXAMPLE_PROV_TRANSPORT_BLE + help + Wi-Fi provisioning component offers both, SoftAP and BLE transports. Choose any one. + + config EXAMPLE_PROV_TRANSPORT_BLE + bool "BLE" + select BT_ENABLED + depends on IDF_TARGET_ESP32 + config EXAMPLE_PROV_TRANSPORT_SOFTAP + bool "Soft AP" + endchoice + + config EXAMPLE_PROV_TRANSPORT + int + default 1 if EXAMPLE_PROV_TRANSPORT_BLE + default 2 if EXAMPLE_PROV_TRANSPORT_SOFTAP + +endmenu diff --git a/examples/provisioning/wifi_prov_mgr/main/app_main.c b/examples/provisioning/wifi_prov_mgr/main/app_main.c index 53ea813ea..109fffac1 100644 --- a/examples/provisioning/wifi_prov_mgr/main/app_main.c +++ b/examples/provisioning/wifi_prov_mgr/main/app_main.c @@ -20,8 +20,14 @@ #include #include + +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE #include +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */ + +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP #include +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */ static const char *TAG = "app"; @@ -93,6 +99,27 @@ static void get_device_service_name(char *service_name, size_t max) ssid_prefix, eth_mac[3], eth_mac[4], eth_mac[5]); } +/* Handler for the optional provisioning endpoint registered by the application. + * The data format can be chosen by applications. Here, we are using plain ascii text. + * Applications can choose to use other formats like protobuf, JSON, XML, etc. + */ +esp_err_t custom_prov_data_handler(uint32_t session_id, const uint8_t *inbuf, ssize_t inlen, + uint8_t **outbuf, ssize_t *outlen, void *priv_data) +{ + if (inbuf) { + ESP_LOGI(TAG, "Received data: %.*s", inlen, (char *)inbuf); + } + char response[] = "SUCCESS"; + *outbuf = (uint8_t *)strdup(response); + if (*outbuf == NULL) { + ESP_LOGE(TAG, "System out of memory"); + return ESP_ERR_NO_MEM; + } + *outlen = strlen(response) + 1; /* +1 for NULL terminating byte */ + + return ESP_OK; +} + void app_main(void) { /* Initialize NVS partition */ @@ -120,6 +147,9 @@ void app_main(void) /* Initialize Wi-Fi including netif with default config */ esp_netif_create_default_wifi_sta(); +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP + esp_netif_create_default_wifi_ap(); +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */ wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); @@ -127,7 +157,12 @@ void app_main(void) wifi_prov_mgr_config_t config = { /* What is the Provisioning Scheme that we want ? * wifi_prov_scheme_softap or wifi_prov_scheme_ble */ +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE .scheme = wifi_prov_scheme_ble, +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */ +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP + .scheme = wifi_prov_scheme_softap, +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */ /* Any default scheme specific event handler that you would * like to choose. Since our example application requires @@ -137,7 +172,12 @@ void app_main(void) * appropriate scheme specific event handler allows the manager * to take care of this automatically. This can be set to * WIFI_PROV_EVENT_HANDLER_NONE when using wifi_prov_scheme_softap*/ +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE .scheme_event_handler = WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */ +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP + .scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_SOFTAP */ }; /* Initialize provisioning manager with the @@ -181,6 +221,7 @@ void app_main(void) */ const char *service_key = NULL; +#ifdef CONFIG_EXAMPLE_PROV_TRANSPORT_BLE /* This step is only useful when scheme is wifi_prov_scheme_ble. This will * set a custom 128 bit UUID which will be included in the BLE advertisement * and will correspond to the primary GATT service that provides provisioning @@ -197,10 +238,23 @@ void app_main(void) 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12 }; wifi_prov_scheme_ble_set_service_uuid(custom_service_uuid); +#endif /* CONFIG_EXAMPLE_PROV_TRANSPORT_BLE */ + /* An optional endpoint that applications can create if they expect to + * get some additional custom data during provisioning workflow. + * The endpoint name can be anything of your choice. + * This call must be made before starting the provisioning. + */ + wifi_prov_mgr_endpoint_create("custom-data"); /* Start provisioning service */ ESP_ERROR_CHECK(wifi_prov_mgr_start_provisioning(security, pop, service_name, service_key)); + /* The handler for the optional endpoint created above. + * This call must be made after starting the provisioning, and only if the endpoint + * has already been created above. + */ + wifi_prov_mgr_endpoint_register("custom-data", custom_prov_data_handler, NULL); + /* Uncomment the following to wait for the provisioning to finish and then release * the resources of the manager. Since in this case de-initialization is triggered * by the default event loop handler, we don't need to call the following */ 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 881fa9d60..c0f4770f2 100644 --- a/examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py +++ b/examples/provisioning/wifi_prov_mgr/wifi_prov_mgr_test.py @@ -29,7 +29,7 @@ esp_prov.config_throw_except = True @ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT") def test_examples_wifi_prov_mgr(env, extra_data): # Acquire DUT - dut1 = env.get_dut("wifi_prov_mgr", "examples/provisioning/manager", dut_class=ttfw_idf.ESP32DUT) + dut1 = env.get_dut("wifi_prov_mgr", "examples/provisioning/wifi_prov_mgr", dut_class=ttfw_idf.ESP32DUT) # Get binary file binary_file = os.path.join(dut1.app.binary_path, "wifi_prov_mgr.bin") @@ -78,6 +78,10 @@ def test_examples_wifi_prov_mgr(env, extra_data): if not esp_prov.establish_session(transport, security): raise RuntimeError("Failed to start session") + print("Sending Custom Data") + if not esp_prov.custom_data(transport, security, "My Custom Data"): + raise RuntimeError("Failed to send custom data") + print("Sending Wifi credential to DUT") if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password): raise RuntimeError("Failed to send Wi-Fi config") From 62626ac4b98a480bbfd32031fdd9da323f8c7639 Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Sun, 5 Jan 2020 23:36:48 +0530 Subject: [PATCH 3/3] esp_prov: Add support for sending some abstract custom data To be used with the provisioning/wifi_prov_mgr example Signed-off-by: Piyush Shah --- tools/esp_prov/esp_prov.py | 22 ++++++++++++++++++++++ tools/esp_prov/prov/custom_prov.py | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/esp_prov/esp_prov.py b/tools/esp_prov/esp_prov.py index 52fb394f2..8ecae3b0d 100644 --- a/tools/esp_prov/esp_prov.py +++ b/tools/esp_prov/esp_prov.py @@ -186,6 +186,16 @@ def custom_config(tp, sec, custom_info, custom_ver): return None +def custom_data(tp, sec, custom_data): + try: + message = prov.custom_data_request(sec, custom_data) + response = tp.send_data('custom-data', message) + return (prov.custom_data_response(sec, response) == 0) + except RuntimeError as e: + on_except(e) + return None + + def scan_wifi_APs(sel_transport, tp, sec): APs = [] group_channels = 0 @@ -328,6 +338,11 @@ if __name__ == '__main__': 'If Wi-Fi scanning is supported by the provisioning service, this need not ' 'be specified')) + parser.add_argument("--custom_data", dest='custom_data', type=str, default='', + help=desc_format( + 'This is an optional parameter, only intended for use with ' + '"examples/provisioning/wifi_prov_mgr_custom_data"')) + parser.add_argument("--custom_config", action="store_true", help=desc_format( 'This is an optional parameter, only intended for use with ' @@ -394,6 +409,13 @@ if __name__ == '__main__': exit(5) print("==== Custom config sent successfully ====") + if args.custom_data != '': + print("\n==== Sending Custom data to esp32 ====") + if not custom_data(obj_transport, obj_security, args.custom_data): + print("---- Error in custom data ----") + exit(5) + print("==== Custom data sent successfully ====") + if args.ssid == '': if not has_capability(obj_transport, 'wifi_scan'): print("---- Wi-Fi Scan List is not supported by provisioning service ----") diff --git a/tools/esp_prov/prov/custom_prov.py b/tools/esp_prov/prov/custom_prov.py index fe611dbe9..06ec1ca71 100644 --- a/tools/esp_prov/prov/custom_prov.py +++ b/tools/esp_prov/prov/custom_prov.py @@ -44,3 +44,17 @@ def custom_config_response(security_ctx, response_data): cmd_resp.ParseFromString(decrypt) print_verbose(security_ctx, "CustomConfig status " + str(cmd_resp.status)) return cmd_resp.status + + +def custom_data_request(security_ctx, data): + # Encrypt the custom data + enc_cmd = security_ctx.encrypt_data(data) + print_verbose(security_ctx, "Client -> Device (CustomData cmd) " + utils.str_to_hexstr(enc_cmd)) + return enc_cmd + + +def custom_data_response(security_ctx, response_data): + # Decrypt response packet + decrypt = security_ctx.decrypt_data(tobytes(response_data)) + print("CustomData response: " + str(decrypt)) + return 0