Skip to content

Commit

Permalink
Merge branch 'support/improve_wifi_prov_cli' into 'master'
Browse files Browse the repository at this point in the history
wifi-prov cli: Set Wi-Fi creds directly for already provisioned devices

See merge request app-frameworks/esp-rainmaker!387
  • Loading branch information
shahpiyushv committed Oct 27, 2023
2 parents ea54ebe + 1036170 commit 2278be2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion components/esp_rainmaker/src/console/esp_rmaker_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,35 @@ static int wifi_prov_handler(int argc, char** argv)
if (argc == 3) {
memcpy(wifi_config.sta.password, argv[2], strlen(argv[2]));
}
wifi_prov_mgr_configure_sta(&wifi_config);

/* If device is still provisioning, use wifi_prov_mgr_configure_sta */
bool provisioned = false;
wifi_prov_mgr_is_provisioned(&provisioned);
if (!provisioned) { // provisioning in progress
wifi_prov_mgr_configure_sta(&wifi_config);
return ESP_OK;
}

/* If already provisioned, just set the new credentials */
/* Stop the Wi-Fi */
if (esp_wifi_stop() != ESP_OK) {
printf("%s: Failed to stop wifi\n", TAG);
}
/* Configure Wi-Fi station with provided host credentials */
if (esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) != ESP_OK) {
printf("%s: Failed to set WiFi configuration\n", TAG);
return ESP_FAIL;
}
/* (Re)Start Wi-Fi */
if (esp_wifi_start() != ESP_OK) {
printf("%s: Failed to start WiFi\n", TAG);
return ESP_FAIL;
}
/* Connect to AP */
if (esp_wifi_connect() != ESP_OK) {
printf("%s: Failed to connect WiFi\n", TAG);
return ESP_FAIL;
}
return ESP_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/common/app_wifi/app_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ esp_err_t app_wifi_start(app_wifi_pop_type_t pop_type)

bool provisioned = false;
/* Let's find out if the device is provisioned */
ESP_ERROR_CHECK(wifi_prov_mgr_is_provisioned(&provisioned));
wifi_prov_mgr_is_provisioned(&provisioned);
/* If device is not yet provisioned start provisioning service */
if (!provisioned) {
ESP_LOGI(TAG, "Starting provisioning");
Expand Down

0 comments on commit 2278be2

Please sign in to comment.