-->
Page 1 of 3

How to get a file from spiffs via upread to the computer?

PostPosted: Sun Aug 16, 2015 11:46 am
by brutzler
Hi,

we have learned to build a spiffs-image with mkspiffs, and to upload it to the flash of an ESP8266.
But what about the other way round?
Imagine we make something like a logger. Writing actual values to spiffs into a txt/csv-file. (BTW: what about the lifetime of the flash in that case??)
Is there a possibility to read the spiffs back and un-mkspiffs it again?
1.) For uploading I use the ESP8266Flasher from the NodeMCU Team. Unfortunately its only for flashing not for upread :-(
2.) I do not see any possibility in mkspiffs to unpack.
Or would it be the better way to read it out byte by byte with the ESP an send it over Wifi/serial?

Any hints?

Re: How to get a file from spiffs via upread to the computer

PostPosted: Sun Aug 16, 2015 12:30 pm
by martinayotte
Unfortunately, the mkspiffs tool doesn't provide unpack functionality as you said.
Of course, this functionality could be added, but this will need quite some development effort.
In the mean time, I would suggest to have some functionalities on the ESP itself, either an HTTPServer or other kind of TCPServer to be able to download any requested files.

Re: How to get a file from spiffs via upread to the computer

PostPosted: Sun Aug 16, 2015 12:54 pm
by brutzler
martinayotte wrote:In the mean time, I would suggest to have some functionalities on the ESP itself, either an HTTPServer or other kind of TCPServer to be able to download any requested files.

OK, you already have seen some examples for this? I am good in modifying software but not good enough to develop own. ;)
And I think there is some need of software at the other side (computer). Perhaps Netcat??? Don't think we will be able to make a ftp-server on the ESP to use only the browser :mrgreen:

To the other question (Lifetime of flash)
I compare it with a eeprom of an arduino. You can write a certain times on the same memory cell.
As I know:
- Flash ~10.000
- EEprom ~100.000
When i use spiffs as a filesystem, there will be something like a directory or similiar, which is always rewritten when I append to a file. And this will be always at the same memory-area, I suggest. Sounds like flash will die soon.

I earlier made a project with an EEprom, where I calculated the memory-area over the time/date and could so write always in a different area. Is there a lib to read/write at a certain flash-byte with software? Similiar to the Eeprom read/write function?

Re: How to get a file from spiffs via upread to the computer

PostPosted: Sun Aug 16, 2015 1:22 pm
by martinayotte
Take the HelloServer example, and add the following handler function along with server.on("/download", handleDownload); in setup().

Code: Select allvoid handleDownload(){
  if (!SPIFFS.begin()) {
    Serial.println("SPIFFS failed to mount !\r\n");                   
  }
  else {
    String str = "";
    File f = SPIFFS.open(server.arg(0), "r");
    if (!f) {
      Serial.println("Can't open SPIFFS file !\r\n");         
    }
    else {
      char buf[1024];
      int siz = f.size();
      while(siz > 0) {
        size_t len = std::min((int)(sizeof(buf) - 1), siz);
        f.read((uint8_t *)buf, len);
        buf[len] = 0;
        str += buf;
        siz -= sizeof(buf) - 1;
      }
      f.close();
      server.send(200, "text/plain", str);
    }
  }
}


Then, in a browser, simply type this url :

Code: Select allhttp://<esp_ipaddr>/download?file=/Config.txt


Of course, this will sent plain text file to the browser, but you can handle other file types if the server.send(200, "text/plain", str); manage it properly ...

About the Flash-vs-EEPROM life time duration, of course it can becomes an issue. In such case better getting back to the SDCard option and use SdFat library ...