Skip to content

fix: Split provisioning into two parts for better synchronization #10677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading