Preferences "begin" sometimes return false when trying to open a namespace

Madbyte
Posts: 4
Joined: Mon Aug 28, 2023 2:56 pm

Preferences "begin" sometimes return false when trying to open a namespace

Postby Madbyte » Wed Sep 20, 2023 3:03 am

Hi,

I'm trying using Preferences. I have the setup values in setup() like this:

Code: Select all

// Preferencias Parámetros
  prefParam.begin("Param", false);
  if (!prefParam.getUShort("VMax", 0))
    prefParam.putUShort("VMax", 410);
  if (!prefParam.getUShort("VMin", 0))
    prefParam.putUShort("VMin", 370);
  if(!prefParam.getUChar("PAMax", 0))
    prefParam.putUChar("PAMax", 150);
  if(!prefParam.getUShort("FMax", 0))
    prefParam.putUShort("FMax", 520);
  if(!prefParam.getUShort("FMin", 0))
    prefParam.putUShort("FMin", 480);
  prefParam.end();
And I have this in my loop():

Code: Select all

  prefParam.begin("Param", true);
  Serial.println (prefParam.getUShort("VMax"));   
  Serial.println (prefParam.getUShort("VMin"));   
  Serial.println (prefParam.getUShort("FMax"));   
  Serial.println (prefParam.getUShort("FMin"));   
  Serial.println (prefParam.getUChar("PAMax"));   
  prefParam.end();
  
  
  vTaskDelay (1000);
Sometimes, I'm getting zero values for some or all keys. I have some task that access those too and asign to a variable and sometimes the variable is zero.

Searching for the possible cause I discovered that sometimes begin return a false value, according the Docs:

"true if the namespace was opened successfully; false otherwise."

So when doing a get when the namespace could not be opened I will get a value of zero.

But I would like to know why I sometimes I'm getting false as a result

Thanks

Who is online

Users browsing this forum: No registered users and 65 guests