Good morning everyone,
sorry my bad english.
is it possible to force the write in the memory flash?
I have placed the flash_write_interval on a very long period and I would like to record my global variables in the flash ram at the close of a pin.
Thank you.
1 Like
did you find if this is possible?
i also would like to do that.
I decided to directly manage the storage of variables with this code:
in the file function.h
#include "esphome.h"
#include "preferences.h"
Preferences Disco;
void setUpMemoria(){
Disco.begin("crono", false);
id(timeON) = Disco.getUInt("timeON",0);
id(timeOFF) = Disco.getUInt("timeOFF",0);
id(timeONX) = Disco.getUInt("timeONX",0);
id(timeOFFX) = Disco.getUInt("timeOFFX",0);
id(Temperatura) = Disco.getDouble("Temperatura",0);
id(TemperaturaX) = Disco.getDouble("TemperaturaX",0);
id(TempOn) = Disco.getInt("TempOn",0);
Disco.end();
}
void writeDisco(){
Disco.begin("crono", false);
Disco.putUInt("timeON",id(timeON));
Disco.putUInt("timeOFF",id(timeOFF));
Disco.putUInt("timeONX",id(timeONX));
Disco.putUInt("timeOFFX",id(timeOFFX));
Disco.putDouble("Temperatura",id(Temperatura));
Disco.putDouble("TemperaturaX",id(TemperaturaX));
Disco.putInt("TempOn",id(TempOn));
Disco.end();
}
in the file yaml
esphome:
name: cronotermostato
includes:
- function.h
libraries:
- Preferences
on_boot:
priority: 800
then:
- lambda: |-
setUpMemoria();
i don’t know if this is the best way, but i haven’t found other solutions.