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

Issue with Tutorial5 #4

Open
mstjerna opened this issue Feb 22, 2018 · 5 comments
Open

Issue with Tutorial5 #4

mstjerna opened this issue Feb 22, 2018 · 5 comments

Comments

@mstjerna
Copy link

Hi

I have some issues with the Tutorial5.
Data are stored in the JSON file:
{"timestamp":[1519303055,1519303075,1519303095],"t":[25.4,25.4,25.4],"h":[19.8,20.2,20.1],"pa":[1050,1050,1050],"bart":[],"barh":[]}

Graph is populated with the values and work as expected until a reboot of the ESP!
When the ESP reboots the file is read and in the loadHistory() function I see that the file is read with the root.prettyPrintTo(Serial);

BUT the graph never get the old data, program starts with a reading of the current temp/humidity and overwrites the file so I lose all the history.

Have anyone else experienced this and if so solved the read-back from file to the current buffer?

@hansaya
Copy link

hansaya commented Feb 23, 2018

I think it designed that way

@mstjerna
Copy link
Author

But why save it the spiff att all then...

@hansaya
Copy link

hansaya commented Feb 24, 2018

Because you cannot hold lot of data on Ram or you going to run out of usable ram

@vvaru
Copy link

vvaru commented Apr 21, 2018

I am getting this output after uploading Part 5 codes:
ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

@Igor-from-moscow
Copy link

Igor-from-moscow commented Nov 17, 2019

To solve this problem, I propose to replace the subprogram of the same name with the one below:

void loadHistory(){
  DynamicJsonBuffer json_Buffer(5000);   
  File file = SPIFFS.open(HISTORY_FILE, "r");
  if (!file){
    Serial.println("No History Exist");
  } else {
    size_t size = file.size();
    if ( size == 0 ) {
      Serial.println("History file empty !");
    } else {
      std::unique_ptr<char[]> buf (new char[size]);
      file.readBytes(buf.get(), size);
JsonObject &temp_root = json_Buffer.parseObject(buf.get());  //область видимости в этой подпрограмме только
      if (!temp_root.success()) {
        Serial.println("Impossible to read JSON file");
      } else {
        Serial.println("History loaded");
        temp_root.prettyPrintTo(Serial);
        Serial.println (" ");  
//---- заполнение рабочего JsonObject
        for (int i=0; i< temp_root["timestamp"].size(); i++){
          timestamp.add( long(temp_root["timestamp"][i]));
          hist_t.add(double(temp_root["t"][i]));
          hist_h.add(double(temp_root["h"][i]));
          hist_pa.add(double(temp_root["pa"][i]));
        }
        if ( temp_root["bart"].size() > 0 ) {
          for ( int k = 0 ; k < 7 ; k++ ) { 
            bart.add(double(temp_root["bart"][k]));
            barh.add(double(temp_root["barh"][k]));
          }  
        } 
       }
      }
    file.close();
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants