Skip to content

preferences.begin gives runtime error: begin(): nvs_open failed: NOT_INITIALIZED #3421

@tehuster

Description

@tehuster

Hardware:

Board: ESP32-WROOM-32
Core Installation version: where can i find this?
IDE name: Platform.io
Flash Frequency: where can i find this?
PSRAM enabled: where can i find this?
Upload Speed: 115200
Computer OS: Windows 10

Description:

When i use preferences.begin i get a runtime error: [E][Preferences.cpp:49] begin(): nvs_open failed: NOT_INITIALIZED.

Sketch:

#include <Arduino.h>
#include <Preferences.h>
#include <Puzzle.h>

Preferences preferences;

void Puzzle::BlinkLed()
{
    Serial.println("Turn led on..");
    Serial.print("Wait for ");
    Serial.println(blinkTime);
    Serial.println("Turn led off");    
}

void Puzzle::setBlinkTime(int bTime)
{
    Puzzle::blinkTime = bTime;    
    preferences.begin("puzzle", false);
    preferences.putUInt("blinkTime", Puzzle::blinkTime);
    preferences.end();
}

int Puzzle::getBlinkTime()
{
    return Puzzle::blinkTime;
}

void Puzzle::loadVariables()
{
    Serial.println("Getting prefernces variables");
    preferences.begin("puzzle", false);
    Puzzle::blinkTime = preferences.getUInt("blinkTime", 0);
    preferences.end();
}
#include <Arduino.h>
#include <TCP.h>
#include <JSON.h>
#include <Request.h>

TCP tcp;
JSON json;
Puzzle puzzle;
Request request(puzzle);  

long previousMillis = 0; 

int blinkTime = 1000;

void setup()
{
    Serial.begin(115200);
    delay(10);

    tcp.connectWifi();
    json.createStatus();   
}

void loop()
{   
    if(tcp.newMessage)
    {
        request.request = json.parseJson(tcp.messageRX);
        request.handleRequest();
        tcp.newMessage = false;
    }
    
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > tcp.interval) {
        previousMillis = currentMillis; 
        tcp.sendData(json.jsonTX);
    }
}

Debug Messages:

[E][Preferences.cpp:49] begin(): nvs_open failed: NOT_INITIALIZED

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions