diff --git a/main/main.c b/main/main.c index 46c9ac5..fc0da20 100644 --- a/main/main.c +++ b/main/main.c @@ -32,6 +32,9 @@ #define ADC_CHAN1 ADC_CHANNEL_5 #define ADC_ATTEN_DB ADC_ATTEN_DB_12 +#define THRESHOLD_UP_NVS_NAME "threshold_up" +#define THRESHOLD_LOW_NVS_NAME "threshold_low" + #define SENSOR_ADC_CHAN 0 static adc_oneshot_unit_handle_t adc_handle; @@ -360,10 +363,10 @@ static esp_err_t save_thresholds_handler(httpd_req_t *req) { return 1; } - err = nvs_set_i32(my_handle, "threshold_low", low_value); + err = nvs_set_i32(my_handle, THRESHOLD_LOW_NVS_NAME, low_value); ESP_ERROR_CHECK(err); - err = nvs_set_i32(my_handle, "threshold_up", up_value); + err = nvs_set_i32(my_handle, THRESHOLD_UP_NVS_NAME, up_value); ESP_ERROR_CHECK(err); // 4. Сохраняем изменения во flash @@ -613,15 +616,21 @@ void app_main(void) { ESP_LOGE("TAG", "Error opening NVS"); } - err = nvs_get_i32(my_handle, "treshhold_low", atomic_load(&g_threshold_low)); - if (err == ESP_ERR_NVS_NOT_FOUND) { + int32_t threshold_up, threshold_low = 0; + + err = nvs_get_i32(my_handle, THRESHOLD_LOW_NVS_NAME, &threshold_low); + if (err == ESP_OK) { + atomic_store(&g_threshold_low, threshold_low); + } else if (err == ESP_ERR_NVS_NOT_FOUND) { atomic_store(&g_threshold_low, 100); } else { ESP_ERROR_CHECK(err); } - err = nvs_get_i32(my_handle, "treshhold_low", atomic_load(&g_threshold_up)); - if (err == ESP_ERR_NVS_NOT_FOUND) { + err = nvs_get_i32(my_handle, THRESHOLD_UP_NVS_NAME, &threshold_up); + if (err == ESP_OK) { + atomic_store(&g_threshold_up, threshold_up); + } else if (err == ESP_ERR_NVS_NOT_FOUND) { atomic_store(&g_threshold_up, 300); } else { ESP_ERROR_CHECK(err); diff --git a/partitions.csv b/partitions.csv index 72fbbb8..ed9b46c 100644 --- a/partitions.csv +++ b/partitions.csv @@ -1,5 +1,5 @@ # ESP-IDF Partition Table -# Name, Type, SubType, Offset, Size, Flags -nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 1M, +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x6000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 1M, diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 0000000..0891353 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,4 @@ +# This file was generated using idf.py save-defconfig or menuconfig [D] key. It can be edited manually. +# Espressif IoT Development Framework (ESP-IDF) 6.2.0 Project Minimal Configuration +# +CONFIG_PARTITION_TABLE_CUSTOM=y