Browse Source

Dump settings line by line to prevent memory issues (#896)

rfm69
Xose Pérez 6 years ago
parent
commit
5da801bffc
2 changed files with 17 additions and 13 deletions
  1. +5
    -5
      code/espurna/settings.ino
  2. +12
    -8
      code/espurna/web.ino

+ 5
- 5
code/espurna/settings.ino View File

@ -38,7 +38,7 @@ unsigned long settingsSize() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
unsigned int _settingsKeyCount() {
unsigned int settingsKeyCount() {
unsigned count = 0; unsigned count = 0;
unsigned pos = SPI_FLASH_SEC_SIZE - 1; unsigned pos = SPI_FLASH_SEC_SIZE - 1;
while (size_t len = EEPROMr.read(pos)) { while (size_t len = EEPROMr.read(pos)) {
@ -50,7 +50,7 @@ unsigned int _settingsKeyCount() {
return count; return count;
} }
String _settingsKeyName(unsigned int index) {
String settingsKeyName(unsigned int index) {
String s; String s;
@ -80,11 +80,11 @@ std::vector<String> _settingsKeys() {
std::vector<String> keys; std::vector<String> keys;
//unsigned int size = settingsKeyCount(); //unsigned int size = settingsKeyCount();
unsigned int size = _settingsKeyCount();
unsigned int size = settingsKeyCount();
for (unsigned int i=0; i<size; i++) { for (unsigned int i=0; i<size; i++) {
//String key = settingsKeyName(i); //String key = settingsKeyName(i);
String key = _settingsKeyName(i);
String key = settingsKeyName(i);
bool inserted = false; bool inserted = false;
for (unsigned char j=0; j<keys.size(); j++) { for (unsigned char j=0; j<keys.size(); j++) {
@ -277,7 +277,7 @@ void _settingsInitCommands() {
DEBUG_MSG_P(PSTR("+OK\n")); DEBUG_MSG_P(PSTR("+OK\n"));
}); });
#endif #endif
settingsRegisterCommand(F("RESET"), [](Embedis* e) { settingsRegisterCommand(F("RESET"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n")); DEBUG_MSG_P(PSTR("+OK\n"));
deferredReset(100, CUSTOM_RESET_TERMINAL); deferredReset(100, CUSTOM_RESET_TERMINAL);


+ 12
- 8
code/espurna/web.ino View File

@ -67,20 +67,24 @@ void _onGetConfig(AsyncWebServerRequest *request) {
AsyncResponseStream *response = request->beginResponseStream("text/json"); AsyncResponseStream *response = request->beginResponseStream("text/json");
DynamicJsonBuffer jsonBuffer;
JsonObject &root = jsonBuffer.createObject();
root["app"] = APP_NAME;
root["version"] = APP_VERSION;
settingsGetJson(root);
root.prettyPrintTo(*response);
jsonBuffer.clear();
char buffer[100]; char buffer[100];
snprintf_P(buffer, sizeof(buffer), PSTR("attachment; filename=\"%s-backup.json\""), (char *) getSetting("hostname").c_str()); snprintf_P(buffer, sizeof(buffer), PSTR("attachment; filename=\"%s-backup.json\""), (char *) getSetting("hostname").c_str());
response->addHeader("Content-Disposition", buffer); response->addHeader("Content-Disposition", buffer);
response->addHeader("X-XSS-Protection", "1; mode=block"); response->addHeader("X-XSS-Protection", "1; mode=block");
response->addHeader("X-Content-Type-Options", "nosniff"); response->addHeader("X-Content-Type-Options", "nosniff");
response->addHeader("X-Frame-Options", "deny"); response->addHeader("X-Frame-Options", "deny");
response->printf("{\n \"app\": \"%s\",\n \"version\": \"%s\"", APP_NAME, APP_VERSION);
// Write the keys line by line (not sorted)
unsigned long count = settingsKeyCount();
for (unsigned int i=0; i<count; i++) {
String key = settingsKeyName(i);
String value = getSetting(key);
response->printf(",\n \"%s\": \"%s\"", key.c_str(), value.c_str());
}
response->printf("\n}");
request->send(response); request->send(response);
} }


Loading…
Cancel
Save