Unverified Commit dcff2e97 authored by Sweety's avatar Sweety Committed by GitHub

Separate Provisioning library from WiFi library (#4547)

parent 6d256b64
......@@ -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
)
......
......@@ -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;
......@@ -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;
......
#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() {
......
name=WiFiProv
version=1.0
author=Switi Mhaiske <sweetymhaiske@gmail.com>
maintainer=Hristo Gochkov <hristo@espressif.com>
sentence=Enables provisioning.
paragraph=With this library you can perform provisioning on esp32 via SoftAP or BLE.
category=
url=
architectures=esp32
......@@ -31,7 +31,8 @@
#include <wifi_provisioning/scheme_softap.h>
#include <wifi_provisioning/manager.h>
#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;
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment