Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTC memory] Rethink what needs to be stored in RTC to survive reboot and sleep #1597

Open
TD-er opened this issue Jul 20, 2018 · 4 comments
Labels
Category: Settings Related to settings/configuration Category: Stabiliy Things that work, but not as long as desired Type: Enhancement Improve something already present

Comments

@TD-er
Copy link
Member

TD-er commented Jul 20, 2018

Currently the functions saveUserVarToRTC() and readFromRTC() handle storing last known variables of the plugins to RTC

saveToRTC() and readFromRTC() handle the storage of the RTCStruct:

// this offsets are in blocks, bytes = blocks * 4
#define RTC_BASE_STRUCT 64
#define RTC_BASE_USERVAR 74

//max 40 bytes: ( 74 - 64 ) * 4
struct RTCStruct
{
  byte ID1;
  byte ID2;
  boolean unused1;
  byte factoryResetCounter;
  byte deepSleepState;
  byte unused2;
  byte flashDayCounter;
  unsigned long flashCounter;
  unsigned long bootCounter;
} RTC;

This struct has no proper constructor, so it could contain any information at boot.
Also, since the RTC storage is very sparse, the layout of this data should be done different.
Start with the biggest items (unsigned long) and add smaller ones.
Current implementation is a waste of space.

Also not all active tasks/plugins must have their values stored.
Often the previous value is only useful when using a formula and not all plugins have 4 values.

Also consider storing last WiFi connection information, like BSSID and channel. That information could help improving WiFi connection speed.
Maybe also store last used IP config? (DHCP may take a few seconds to complete)

Other data could contain information on last changed setting, or whether to boot in safe mode at some crash. (first set next boot mode to safe mode when loading settings and after successful load, set it to normal mode)

See NodeMCU - RTC User Memory Module for some information about size.

@TD-er TD-er added Type: Enhancement Improve something already present Category: Settings Related to settings/configuration Category: Stabiliy Things that work, but not as long as desired labels Jul 20, 2018
@uzi18
Copy link
Contributor

uzi18 commented Jul 20, 2018

If store IP from dhcp, so also maybe lease time for ip renew procedure?
don't know if it is supported right now?

@TD-er
Copy link
Member Author

TD-er commented Jul 20, 2018

I have looked into getting more info about the DHCP request (also to get NTP server suggestion and a hostname), but I did not find a way to get access to that info.

But when setting deep sleep, and not waken by some external trigger, then you could store the last timestamp before sleep and thus have a reasonable good idea of the current time when waking from the sleep.

@TD-er
Copy link
Member Author

TD-er commented Jul 29, 2018

There is already a work-around present in the code to get out of boot loops:

/********************************************************************************************\
  If RX and TX tied together, perform emergency reset to get the system out of boot loops
  \*********************************************************************************************/
void emergencyReset()

Meaning, when both of these pins are tied together, it will try a factory reset.

@uzi18
Copy link
Contributor

uzi18 commented Jul 29, 2018

so we not need any other pin to emergency reset :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Settings Related to settings/configuration Category: Stabiliy Things that work, but not as long as desired Type: Enhancement Improve something already present
Projects
None yet
Development

No branches or pull requests

2 participants