Save string with Preferences

tosik@seznam.cz
Posts: 1
Joined: Mon Sep 19, 2022 2:56 pm

Save string with Preferences

Postby tosik@seznam.cz » Mon Sep 19, 2022 3:03 pm

Hallo.
I have a problem with the storage of the string to memory using Preferences. What do I make a mistake? I need to create a string from the current date and time and save it.

Code: Select all


#include <Preferences.h>              

Preferences preferences;               
// Simulation of data loaded from the time module
uint8_t den = 28;
uint8_t mesic = 11;
uint8_t sekundy = 23;
uint8_t hodiny = 15;
uint8_t minuty = 45;
int rok = 1985;

void setup() {
  Serial.begin(115200);
  preferences.begin("EEpamet", false);       
  delay(500); 
// create string
  String datumSynchro = "";
  datumSynchro = (String)hodiny;
  datumSynchro += ":";
  datumSynchro += (String)minuty; 
  datumSynchro += ":";
  datumSynchro += (String)sekundy;
  datumSynchro += "*";
  datumSynchro += (String)den;
  datumSynchro += "/";
  datumSynchro += (String)mesic;
  datumSynchro += "/";
  datumSynchro += (String)rok;
 
  const char* test = "Nactena vychozi hodnota";
  
  Serial.println(datumSynchro);
  preferences.putString("datumPoslSynchEZ", datumSynchro);
  String nactenaHodnotaZpameti;
  nactenaHodnotaZpameti = preferences.getString("datumPoslSynchEZ", test); 
  Serial.println(nactenaHodnotaZpameti);
  Serial.println("********************************");
}

void loop() {  
}


Who is online

Users browsing this forum: No registered users and 75 guests