persistence, retain last state on stand alone application
Moderators: grovkillen, Stuntteam, TD-er
-
- New user
- Posts: 5
- Joined: 14 Jul 2018, 00:11
persistence, retain last state on stand alone application
Hi, I am working on a standalone thermostat.
The user has 2 buttons to set the temperature (it is stored on a dummy device), and then it will control a heater to regulate the temperature.
How can I store the last temperature set by the user to retain it after power loss? there is any way to store a value on the internal flash?
The user has 2 buttons to set the temperature (it is stored on a dummy device), and then it will control a heater to regulate the temperature.
How can I store the last temperature set by the user to retain it after power loss? there is any way to store a value on the internal flash?
Re: persistence, retain last state on stand alone application
Not at the moment.
The only thing that somewhat is stored, are the plugin output values. Those are stored in RTC memory, which will survive a crash or warm reboot.
As soon as the power is lost, even those are gone.
But I guess having some plugin to store values, would be a nice addition.
The only thing that somewhat is stored, are the plugin output values. Those are stored in RTC memory, which will survive a crash or warm reboot.
As soon as the power is lost, even those are gone.
But I guess having some plugin to store values, would be a nice addition.
Re: persistence, retain last state on stand alone application
I am currently working on an integrated thermostat plugin with OLED an 3 button.TD-er wrote: ↑15 Aug 2018, 22:29 The only thing that somewhat is stored, are the plugin output values. Those are stored in RTC memory, which will survive a crash or warm reboot.
As soon as the power is lost, even those are gone.
But I guess having some plugin to store values, would be a nice addition.
https://github.com/enesbcs/ESPEasyPlugi ... rmOLED.ino
Hardware part is ready, testing is in progress now.

Are there any simple example code, how can i store values to flash? I think it can be stored when the setpoint changes, ideally it will not be too frequent.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: persistence, retain last state on stand alone application
And I know that membrane button sticker 

ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



Re: persistence, retain last state on stand alone application
I've been thinking about this. I guess we could add some thing to the dummy plugin, to set some numeric value, which will be active when the plugin runs its init procedure (at boot, when applying settings, etc)
Then add some command to set these values from rules and add some routine to check every N seconds to see if it has changed and save the settings of that plugin. (or add a command to write it to the settings)
So a command would then need:
- Plugin Index
- Preset value index
- new value.
This value should then have the same range as the normal Dummy.
Only caveat will be what to do when the new preset differs from the current set output value?
Another option could be to make some command to "copy current values to preset values of dummy with idx N"
Re: persistence, retain last state on stand alone application
I'm thinking about simple save when changed & restore on init from Spiffs to 4 plugin values. I am not sure how it works exactly, as i am not a real programmer, just a hobbist. 
in PLUGIN_INIT:
in PLUGIN_READ - when value change detected:

in PLUGIN_INIT:
Code: Select all
if (SPIFFS.exists("thermo.dat"))
{
fs::File f = SPIFFS.open("thermo.dat", "r");
if (f)
{
f.readBytes( &UserVar+BaseVarIndex, (sizeof(UserVar[BaseVarIndex])*4) );
f.close();
}
}
Code: Select all
fs::File f = SPIFFS.open("thermo.dat", "w");
if (f)
{
f.write( &UserVar+BaseVarIndex, (sizeof(UserVar[BaseVarIndex])*4) );
f.close();
}
Re: persistence, retain last state on stand alone application
I spent some time with it, but with the following modifications, it seems to work OK.
flashCount() function is not used anymore?
Now the setpoint data and relay state survives power off&power on.
I am sure that beyond the nice DIN rail box and button sticker, the 1.3" OLED display is also familiar to everyone.
Altough the 0.96" sized display sharper, i have to use a new font with 18 height, becaues smaller fonts simply seems very ugly on the 1.3" display. I like very much the P036 FrameOLED plugin, and many thanks for it, but i have to modify it very much to work as i planned. The most important thing to me to see the image of the flame when relay is active... 
I planned the following features, which seems to work now:
- 3 button (with built in pull-up enabled): 1/ left=decrease setpoint in mode2, decrease time in mode3, 2/ right=increase setpoint in mode2, increase time in mode3, 3/ mode change button (mode1=off,mode2=auto-setpoint controlled,mode3=manual on for specific time in minutes)
- reports its state in mqtt
- can be controlled by commands, rules, url..
- remember it's status on power outage
Commands:
oledframedcmd is the same as in frameoled, as copied from there
thermo,setpoint,22 // set the setpoint to 22 celsius
thermo,setpoint,p0.5 // increase actual setpoint with 0.5 celsius
thermo,setpoint,m0.5 // decrease actual setpoint with 0.5 celsius
thermo,mode,0 // set relay permanently off
thermo,mode,1 // set relay on automatically if current temperature below setpoint
thermo,mode,2,5 // set relay on manually for 5 minutes
Code: Select all
f.read( ((uint8_t *)&UserVar[event->BaseVarIndex] + 0), 16 );
f.write( ((uint8_t *)&UserVar[event->BaseVarIndex] + 0), 16 );
Now the setpoint data and relay state survives power off&power on.
I am sure that beyond the nice DIN rail box and button sticker, the 1.3" OLED display is also familiar to everyone.


I planned the following features, which seems to work now:
- 3 button (with built in pull-up enabled): 1/ left=decrease setpoint in mode2, decrease time in mode3, 2/ right=increase setpoint in mode2, increase time in mode3, 3/ mode change button (mode1=off,mode2=auto-setpoint controlled,mode3=manual on for specific time in minutes)
- reports its state in mqtt
- can be controlled by commands, rules, url..
- remember it's status on power outage
Commands:
oledframedcmd is the same as in frameoled, as copied from there
thermo,setpoint,22 // set the setpoint to 22 celsius
thermo,setpoint,p0.5 // increase actual setpoint with 0.5 celsius
thermo,setpoint,m0.5 // decrease actual setpoint with 0.5 celsius
thermo,mode,0 // set relay permanently off
thermo,mode,1 // set relay on automatically if current temperature below setpoint
thermo,mode,2,5 // set relay on manually for 5 minutes
- Attachments
-
- IMG_20180817_214152_1.jpg (84.76 KiB) Viewed 7248 times
Re: persistence, retain last state on stand alone application
The flash count is still checked, but you'll have to call that counter function.
And writing like that can be tricky. I don't know how writes are handled at a lower level when writing less than a page on the flash chip.
I will also have a look at your changes for the OLED plugin, to see what you're missing in the current one
And writing like that can be tricky. I don't know how writes are handled at a lower level when writing less than a page on the flash chip.
I will also have a look at your changes for the OLED plugin, to see what you're missing in the current one

Re: persistence, retain last state on stand alone application
The FrameOLED plugin is perfect for an universal device. Perhaps a command for changing pages "scrolling", scroll to specified page or stop scrolling can be handy sometimes.
My modifications was created especially for thermostats, this is not something that can be used generally. ThermOLED is an integrated plugin. (3-in-1: display+buttons+relay)
- Attachments
-
- thermo_plugin_settings.jpg (44.33 KiB) Viewed 7222 times
Who is online
Users browsing this forum: Semrush [Bot] and 13 guests