Smart Home Automation Forum
Library <Preferences.h> Not Storing Values - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A4S (https://www.kincony.com/forum/forumdisplay.php?fid=41)
+--- Thread: Library <Preferences.h> Not Storing Values (/showthread.php?tid=4769)



Library <Preferences.h> Not Storing Values - job-systems - 03-01-2024

Hi, hope everyone is fine.

I give up... I need help. I am unable to store values in non volatile memory, so that if there is a power loss, and re-power, the value keeps the same... example, a temperature setpoint.

In my Arduino IDE environment I use: Node32s board (Is this the correct board?

This is the configuration I have in Arduino IDE:

GENERAL: 

#include <Preferences.h>

Preferences preferences; // Start preferences service.

SETUP:

  preferences.begin("almacenamiento-valores", false); // Start storage
  Serial.println("Escribiendo en NVS: 123");
  preferences.putInt("offset", 123); // Write a test value of 123 on the memory space called "offset".
 
  int valorLeido = preferences.getInt("offset", 0); // Reads the stored value.
  Serial.print("Leído de NVS: ");
  Serial.println(valorLeido); // Show the value that was stored.
  preferences.end();


Result I get on serial monitor: 

Escribiendo en NVS: 123
Leído de NVS: 0

Result: Writing the value was not successful. 

What am I doing wrong?
Would you advice using a different library for storing values?
Maybe the board I have selected on Arduino IDE is the wrong one?

Thank you for your help. 

BR, Juan