Skip to content

Commit

Permalink
aws_iot: fix aws_iot examples without NVS initialization
Browse files Browse the repository at this point in the history
WiFi used to initialise nvs automatically, but it doesn't now.
see more info: #624

Closes #624
  • Loading branch information
ustccw committed Nov 22, 2017
1 parent 4332a2c commit 4b3997c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"

#include "nvs.h"
#include "nvs_flash.h"

#include "aws_iot_config.h"
#include "aws_iot_log.h"
#include "aws_iot_version.h"
Expand Down Expand Up @@ -316,6 +319,14 @@ static void initialise_wifi(void)

void app_main()
{
// Initialize NVS.
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );

initialise_wifi();
#ifdef CONFIG_MBEDTLS_DEBUG
const size_t stack_size = 36*1024;
Expand Down
10 changes: 10 additions & 0 deletions examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"

#include "nvs.h"
#include "nvs_flash.h"

#include "aws_iot_config.h"
#include "aws_iot_log.h"
#include "aws_iot_version.h"
Expand Down Expand Up @@ -362,6 +365,13 @@ static void initialise_wifi(void)

void app_main()
{
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );

initialise_wifi();
/* Temporarily pin task to core, due to FPU uncertainty */
xTaskCreatePinnedToCore(&aws_iot_task, "aws_iot_task", 16384+1024, NULL, 5, NULL, 1);
Expand Down

0 comments on commit 4b3997c

Please sign in to comment.