Skip to content

Commit

Permalink
Merge pull request #10677 from kvp1703/fix/wifi_provision
Browse files Browse the repository at this point in the history
fix: Split provisioning into two parts for better synchronization
  • Loading branch information
me-no-dev authored Dec 11, 2024
2 parents d55160c + 4ecfd35 commit 59d51de
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ void setup() {

RMaker.enableSystemService(SYSTEM_SERV_FLAGS_ALL, 2, 2, 2);

#if CONFIG_IDF_TARGET_ESP32S2
WiFiProv.initProvision(NETWORK_PROV_SCHEME_SOFTAP, NETWORK_PROV_SCHEME_HANDLER_NONE);
#else
WiFiProv.initProvision(NETWORK_PROV_SCHEME_BLE, NETWORK_PROV_SCHEME_HANDLER_FREE_BTDM);
#endif

RMaker.start();

WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread.
Expand Down
25 changes: 17 additions & 8 deletions libraries/WiFiProv/src/WiFiProv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ static void get_device_service_name(prov_scheme_t prov_scheme, char *service_nam
#endif
}

void WiFiProvClass ::beginProvision(
prov_scheme_t prov_scheme, scheme_handler_t scheme_handler, network_prov_security_t security, const char *pop, const char *service_name,
const char *service_key, uint8_t *uuid, bool reset_provisioned
) {
bool provisioned = false;
static char service_name_temp[32];

void WiFiProvClass ::initProvision(prov_scheme_t prov_scheme, scheme_handler_t scheme_handler, bool reset_provisioned) {
if (this->provInitDone) {
log_i("provInit was already done!");
return;
}
network_prov_mgr_config_t config;
#if CONFIG_BLUEDROID_ENABLED
if (prov_scheme == NETWORK_PROV_SCHEME_BLE) {
Expand Down Expand Up @@ -118,11 +116,22 @@ void WiFiProvClass ::beginProvision(
if (reset_provisioned) {
log_i("Resetting provisioned data.");
network_prov_mgr_reset_wifi_provisioning();
} else if (network_prov_mgr_is_wifi_provisioned(&provisioned) != ESP_OK) {
} else if (network_prov_mgr_is_wifi_provisioned(&(this->provisioned)) != ESP_OK) {
log_e("network_prov_mgr_is_wifi_provisioned failed!");
network_prov_mgr_deinit();
return;
}
this->provInitDone = true;
}

void WiFiProvClass ::beginProvision(
prov_scheme_t prov_scheme, scheme_handler_t scheme_handler, network_prov_security_t security, const char *pop, const char *service_name,
const char *service_key, uint8_t *uuid, bool reset_provisioned
) {
if (!this->provInitDone) {
WiFiProvClass ::initProvision(prov_scheme, scheme_handler, reset_provisioned);
}
static char service_name_temp[32];
if (provisioned == false) {
#if CONFIG_BLUEDROID_ENABLED
if (prov_scheme == NETWORK_PROV_SCHEME_BLE) {
Expand Down
7 changes: 7 additions & 0 deletions libraries/WiFiProv/src/WiFiProv.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ typedef enum {

//Provisioning class
class WiFiProvClass {
private:
bool provInitDone = false;
bool provisioned = false;

public:
void initProvision(
prov_scheme_t prov_scheme = NETWORK_PROV_SCHEME_SOFTAP, scheme_handler_t scheme_handler = NETWORK_PROV_SCHEME_HANDLER_NONE, bool reset_provisioned = false
);
void beginProvision(
prov_scheme_t prov_scheme = NETWORK_PROV_SCHEME_SOFTAP, scheme_handler_t scheme_handler = NETWORK_PROV_SCHEME_HANDLER_NONE,
network_prov_security_t security = NETWORK_PROV_SECURITY_1, const char *pop = "abcd1234", const char *service_name = NULL, const char *service_key = NULL,
Expand Down

0 comments on commit 59d51de

Please sign in to comment.