From e8d6050a7ba43b89b14615baa197d4b1114ce5e3 Mon Sep 17 00:00:00 2001 From: P-R-O-C-H-Y <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Wed, 2 Mar 2022 14:18:20 +0100 Subject: [PATCH] Implemented new types of SmartConfig (#6367) --- libraries/WiFi/src/WiFiSTA.cpp | 19 ++++++++++++++++--- libraries/WiFi/src/WiFiSTA.h | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/WiFi/src/WiFiSTA.cpp b/libraries/WiFi/src/WiFiSTA.cpp index dd4688236..c75405bb4 100644 --- a/libraries/WiFi/src/WiFiSTA.cpp +++ b/libraries/WiFi/src/WiFiSTA.cpp @@ -655,8 +655,15 @@ IPv6Address WiFiSTAClass::localIPv6() bool WiFiSTAClass::_smartConfigStarted = false; bool WiFiSTAClass::_smartConfigDone = false; - -bool WiFiSTAClass::beginSmartConfig() { +/** + * @brief + * + * @param type Select type of SmartConfig. Default type is SC_TYPE_ESPTOUCH + * @param crypt_key When using type SC_TYPE_ESPTOUTCH_V2 crypt key needed, else ignored. Lenght should be 16 chars. + * @return true if configuration is successful. + * @return false if configuration fails. + */ +bool WiFiSTAClass::beginSmartConfig(smartconfig_type_t type, char* crypt_key) { esp_err_t err; if (_smartConfigStarted) { return false; @@ -668,7 +675,13 @@ bool WiFiSTAClass::beginSmartConfig() { esp_wifi_disconnect(); smartconfig_start_config_t conf = SMARTCONFIG_START_CONFIG_DEFAULT(); - err = esp_smartconfig_set_type(SC_TYPE_ESPTOUCH); + + if (type == SC_TYPE_ESPTOUCH_V2){ + conf.esp_touch_v2_enable_crypt = true; + conf.esp_touch_v2_key = crypt_key; + } + + err = esp_smartconfig_set_type(type); if (err != ESP_OK) { log_e("SmartConfig Set Type Failed!"); return false; diff --git a/libraries/WiFi/src/WiFiSTA.h b/libraries/WiFi/src/WiFiSTA.h index afd641f7e..e49273f01 100644 --- a/libraries/WiFi/src/WiFiSTA.h +++ b/libraries/WiFi/src/WiFiSTA.h @@ -92,7 +92,7 @@ protected: static bool _autoReconnect; public: - bool beginSmartConfig(); + bool beginSmartConfig(smartconfig_type_t type = SC_TYPE_ESPTOUCH, char* crypt_key = NULL); bool stopSmartConfig(); bool smartConfigDone(); -- GitLab