diff --git a/CMakeLists.txt b/CMakeLists.txt index 4911dd58..e7c6ac4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,11 +72,11 @@ set(LIBRARY_SRCS libraries/WiFi/src/WiFi.cpp libraries/WiFi/src/WiFiGeneric.cpp libraries/WiFi/src/WiFiMulti.cpp - libraries/WiFi/src/WiFiProv.cpp libraries/WiFi/src/WiFiScan.cpp libraries/WiFi/src/WiFiServer.cpp libraries/WiFi/src/WiFiSTA.cpp libraries/WiFi/src/WiFiUdp.cpp + libraries/WiFiProv/src/WiFiProv.cpp libraries/Wire/src/Wire.cpp ) @@ -202,6 +202,7 @@ set(COMPONENT_ADD_INCLUDEDIRS libraries/WebServer/src libraries/WiFiClientSecure/src libraries/WiFi/src + libraries/WiFiProv/src libraries/Wire/src ) diff --git a/libraries/WiFi/src/WiFi.cpp b/libraries/WiFi/src/WiFi.cpp index a78e0c3e..44d46ee0 100644 --- a/libraries/WiFi/src/WiFi.cpp +++ b/libraries/WiFi/src/WiFi.cpp @@ -88,4 +88,14 @@ void WiFiClass::printDiag(Print& p) p.println(conf.sta.bssid_set); } +void WiFiClass::enableProv(bool status) +{ + prov_enable = status; +} + +bool WiFiClass::isProvEnabled() +{ + return prov_enable; +} + WiFiClass WiFi; diff --git a/libraries/WiFi/src/WiFi.h b/libraries/WiFi/src/WiFi.h index 54bd1025..457f913a 100644 --- a/libraries/WiFi/src/WiFi.h +++ b/libraries/WiFi/src/WiFi.h @@ -37,11 +37,17 @@ #include "WiFiClient.h" #include "WiFiServer.h" #include "WiFiUdp.h" -#include "WiFiProv.h" -class WiFiClass : public WiFiGenericClass, public WiFiSTAClass, public WiFiScanClass, public WiFiAPClass, public WiFiProvClass +class WiFiClass : public WiFiGenericClass, public WiFiSTAClass, public WiFiScanClass, public WiFiAPClass { +private: + bool prov_enable; public: + WiFiClass() + { + prov_enable = false; + } + using WiFiGenericClass::channel; using WiFiSTAClass::SSID; @@ -60,6 +66,8 @@ public: friend class WiFiClient; friend class WiFiServer; friend class WiFiUDP; + void enableProv(bool status); + bool isProvEnabled(); }; extern WiFiClass WiFi; diff --git a/libraries/WiFi/examples/WiFiProv/README.md b/libraries/WiFiProv/examples/WiFiProv/README.md similarity index 100% rename from libraries/WiFi/examples/WiFiProv/README.md rename to libraries/WiFiProv/examples/WiFiProv/README.md diff --git a/libraries/WiFi/examples/WiFiProv/WiFiProv.ino b/libraries/WiFiProv/examples/WiFiProv/WiFiProv.ino similarity index 88% rename from libraries/WiFi/examples/WiFiProv/WiFiProv.ino rename to libraries/WiFiProv/examples/WiFiProv/WiFiProv.ino index 4b673ef0..48ffe1e7 100644 --- a/libraries/WiFi/examples/WiFiProv/WiFiProv.ino +++ b/libraries/WiFiProv/examples/WiFiProv/WiFiProv.ino @@ -1,4 +1,4 @@ -#include "WiFi.h" +#include "WiFiProv.h" void SysProvEvent(system_event_t *sys_event,wifi_prov_event_t *prov_event) { if(sys_event) { @@ -56,8 +56,8 @@ void setup() { /* uint8_t uuid[16] = {0xb4, 0xdf, 0x5a, 0x1c, 0x3f, 0x6b, 0xf4, 0xbf, 0xea, 0x4a, 0x82, 0x03, 0x04, 0x90, 0x1a, 0x02 };*/ WiFi.onEvent(SysProvEvent); - //WiFi.beginProvision(provSchemeBLE, WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, "abcd1234", "PROV_XXX", NULL, NULL); - WiFi.beginProvision(provSchemeSoftAP, WIFI_PROV_EVENT_HANDLER_NONE, WIFI_PROV_SECURITY_1, "abcd1234", NULL, NULL, NULL); + //WiFiProv.beginProvision(provSchemeBLE, WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, "abcd1234", "PROV_XXX", NULL, NULL); + WiFiProv.beginProvision(provSchemeSoftAP, WIFI_PROV_EVENT_HANDLER_NONE, WIFI_PROV_SECURITY_1, "abcd1234", NULL, NULL, NULL); } void loop() { diff --git a/libraries/WiFiProv/library.properties b/libraries/WiFiProv/library.properties new file mode 100644 index 00000000..8383d2ff --- /dev/null +++ b/libraries/WiFiProv/library.properties @@ -0,0 +1,9 @@ +name=WiFiProv +version=1.0 +author=Switi Mhaiske +maintainer=Hristo Gochkov +sentence=Enables provisioning. +paragraph=With this library you can perform provisioning on esp32 via SoftAP or BLE. +category= +url= +architectures=esp32 diff --git a/libraries/WiFi/src/WiFiProv.cpp b/libraries/WiFiProv/src/WiFiProv.cpp similarity index 96% rename from libraries/WiFi/src/WiFiProv.cpp rename to libraries/WiFiProv/src/WiFiProv.cpp index 59a5e7ff..db6f86f8 100644 --- a/libraries/WiFi/src/WiFiProv.cpp +++ b/libraries/WiFiProv/src/WiFiProv.cpp @@ -31,7 +31,8 @@ #include #include #undef IPADDR_NONE -#include "WiFi.h" +#include "WiFiProv.h" +#include "SimpleBLE.h" extern esp_err_t postToSysQueue(system_prov_event_t *); @@ -42,13 +43,6 @@ static const uint8_t custom_service_uuid[16] = { 0xb4, 0xdf, 0x5a, 0x1c, 0x3f, #define SERV_NAME_PREFIX_PROV "PROV_" -bool WiFiProvClass::prov_enable = true; - -bool WiFiProvClass::isProvEnabled() -{ - return prov_enable; -} - void provSchemeBLE() { prov_scheme = WIFI_PROV_SCHEME_BLE; @@ -109,7 +103,7 @@ static void get_device_service_name(char *service_name, size_t max) void WiFiProvClass :: beginProvision(void (*scheme_cb)(), wifi_prov_event_handler_t scheme_event_handler, wifi_prov_security_t security, const char * pop, const char *service_name, const char *service_key, uint8_t * uuid) { - prov_enable = true; + WiFi.enableProv(true); bool provisioned = false; scheme_cb(); config.scheme_event_handler = scheme_event_handler; @@ -152,7 +146,7 @@ void WiFiProvClass :: beginProvision(void (*scheme_cb)(), wifi_prov_event_handle } else { wifi_prov_mgr_deinit(); WiFi.mode(WIFI_MODE_STA); - log_i("Aleardy Provisioned, starting Wi-Fi STA"); + log_i("Already Provisioned, starting Wi-Fi STA"); #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO wifi_config_t conf; esp_wifi_get_config(WIFI_IF_STA,&conf); @@ -162,4 +156,4 @@ void WiFiProvClass :: beginProvision(void (*scheme_cb)(), wifi_prov_event_handle WiFi.begin(); } } - +WiFiProvClass WiFiProv; diff --git a/libraries/WiFi/src/WiFiProv.h b/libraries/WiFiProv/src/WiFiProv.h similarity index 73% rename from libraries/WiFi/src/WiFiProv.h rename to libraries/WiFiProv/src/WiFiProv.h index edda35aa..89b6315e 100644 --- a/libraries/WiFi/src/WiFiProv.h +++ b/libraries/WiFiProv/src/WiFiProv.h @@ -17,10 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "WiFi.h" #include "wifi_provisioning/manager.h" #include "wifi_provisioning/scheme_ble.h" -#include "nvs_flash.h" -#include "SimpleBLE.h" //Select the scheme using which you want to provision typedef enum { @@ -34,19 +33,11 @@ extern void provSchemeBLE(); //Provisioning class class WiFiProvClass { - protected: - static bool prov_enable; - public: - WiFiProvClass() { - prov_enable = false; - } - bool isProvEnabled(); - - void beginProvision(void (*scheme_cb)() = provSchemeSoftAP, wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char * pop = "abcd1234", const char * service_name = NULL, const char * service_key = NULL, uint8_t *uuid = NULL); + void beginProvision(void (*scheme_cb)() = provSchemeSoftAP, wifi_prov_event_handler_t scheme_event_handler = WIFI_PROV_EVENT_HANDLER_NONE, wifi_prov_security_t security = WIFI_PROV_SECURITY_1, const char * pop = "abcd1234", const char * service_name = NULL, const char * service_key = NULL, uint8_t *uuid = NULL); }; - +extern WiFiProvClass WiFiProv; /* Event Handler for BLE - WIFI_PROV_SCHEME_BLE_EVENT_HANDLER_FREE_BTDM