]> granicus.if.org Git - esp-idf/commitdiff
aws_iot: fix aws_iot examples without NVS initialization
authorChen Wu <chenwu@espressif.com>
Wed, 22 Nov 2017 03:42:55 +0000 (11:42 +0800)
committerChen Wu <chenwu@espressif.com>
Wed, 22 Nov 2017 05:02:55 +0000 (13:02 +0800)
WiFi used to initialise nvs automatically, but it doesn't now.
see more info: https://github.com/espressif/esp-idf/issues/624

Closes #624

examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c
examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c

index ab9161fcb1f4391f2ead25c0e7dd62e940e6ab61..2163c38055f586619eff1320e14b93685903009b 100644 (file)
@@ -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"
@@ -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;
index 2da22472ee6cf11321cbda5a2a67583571f8c7a0..13ba14e5d04d227c6fefe09f9d5dc430897c42f6 100644 (file)
@@ -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"
@@ -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);