ESP8266-Webserver-Tutorials icon indicating copy to clipboard operation
ESP8266-Webserver-Tutorials copied to clipboard

Issue with Tutorial5

Open mstjerna opened this issue 7 years ago • 5 comments

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?

mstjerna avatar Feb 22 '18 12:02 mstjerna

I think it designed that way

hansaya avatar Feb 23 '18 15:02 hansaya

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

mstjerna avatar Feb 23 '18 19:02 mstjerna

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

hansaya avatar Feb 24 '18 16:02 hansaya

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

vvaru avatar Apr 21 '18 12:04 vvaru

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();
  }
}

Igor-from-moscow avatar Nov 17 '19 01:11 Igor-from-moscow