ESP8266 SPIFFS leer

Gast #6252906
Lesenswert?

Hallo,

ich habe das Problem, das ich Daten in den SPI von einem ESP8266 (Wemos 
d1 mini) hochlade, die Daten danach nicht im SPIFFS liegen (Getestet mit 
folgendem Sketch: 
https://github.com/adlerweb/ESP8266Webserver-Tutorial/blob/master/8%20-%20WebServer%20-%20SPIFFS/8.cpp). 
Das Programieren des ESPs und der Upload der Daten in den SPIFFS erfolgt 
mit der aktuellsten Version von PlatformIO in VsCode.

TR.0LL
Gast #6253031
Lesenswert?

Hallo,

hier ist der Inhalt der platformio.ini-Datei:
1
[env:d1_mini]
2
platform = espressif8266@2.0.4
3
board = d1_mini
4
framework = arduino
5
monitor_speed = 115200
6
;build_flags = -fexceptions
7
;build_unflags = -fno-exceptions
8

9

10
lib_deps = 
11
  FastLED@~3.3.3
batman schrieb:
> Wieviel Speicher hast du denn für das FS reserviert?

Wo steht der Wert?
Wie gibt man die größe davon in der platformio.ini-Datei an.
#6253069
Lesenswert?

TR.0LL schrieb:
> Wo steht der Wert?
D1_Mini => 
%USERPROFILE%\.platformio\platforms\espressif8266\boards\d1_mini.json => 
"ldscript": "eagle.flash.4m1m.ld"

TR.0LL schrieb:
> Wie gibt man die größe davon in der platformio.ini-Datei an.
z.B.
build_flags = -Wall -Wl,-Teagle.flash.4m2m.ld

Im Quellcode fehlt IMHO der Upload handler sowie das Upload formular:
1
  server.on("/upload", HTTP_GET, []() {                 // if the client requests the upload page
2
    handleFileUploadDialog();
3
  });
4

5
  server.on("/upload", HTTP_POST,                       // if the client posts to the upload page
6
    [](){ server.send(200); },                          // Send status 200 (OK) to tell the client we are ready to receive
7
    handleFileUpload                                    // Receive and save the file
8
  );
9

10

11
void handleFileUploadDialog(){
12
    String page = FPSTR(HTTP_HEAD);
13
    page.replace("{v}", "File Upload");
14
    page += FPSTR(HTTP_STYLE);
15
    page += FPSTR(HTTP_JS_IMAGE);
16
    page += FPSTR(HTTP_HEAD_END);
17
    page += F("<h1>File Upload</h1><br />");
18
    page += F("<form action=\"/upload\" method=\"POST\" enctype=\"multipart/form-data\">");
19
    page += F("<input type=\"file\" name=\"data\">");
20
    page += F("<input type=\"submit\" value=\"Upload\">");
21
    page += F("</form>");
22
    
23
    page += FPSTR(HTTP_END);
24

25
    server.send(200, "text/html", page);
26

27
}
28

29
void handleFileUpload(){ // upload a new file to the SPIFFS
30
  HTTPUpload& upload = server.upload();
31
  if(upload.status == UPLOAD_FILE_START){
32
    String filename = upload.filename;
33
    if(!filename.startsWith("/")) filename = "/"+filename;
34
    Serial.print("handleFileUpload Name: "); Serial.println(filename);
35
    fsUploadFile = SPIFFS.open(filename, "w");            // Open the file for writing in SPIFFS (create if it doesn't exist)
36
    filename = String();
37
  } else if(upload.status == UPLOAD_FILE_WRITE){
38
    if(fsUploadFile)
39
      fsUploadFile.write(upload.buf, upload.currentSize); // Write the received bytes to the file
40
  } else if(upload.status == UPLOAD_FILE_END){
41
    if(fsUploadFile) {                                    // If the file was successfully created
42
      fsUploadFile.close();                               // Close the file again
43
      Serial.print("handleFileUpload Size: "); Serial.println(upload.totalSize);
44
      handleSuccess();
45
    } else {
46
      server.send(500, "text/plain", "500: couldn't create file");
47
    }
48
  }
49
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren