0

I use the Arduino IDE 1.8.10 and the esp8266 core 2.7.1 and the Wemos-D1 with SD Card Module For the SD Card i use the SdFat.h library, because i need to set the timestamp for the uploaded file.

I am not a expert to arduino programming.

Currently my scetcch can this: List Files from the SD Card on a webpage and show Filename and Filesize. Working. Delete selected File. Working.

My Goal:

Download a File over http from the SD Card to my Windows PC.

Upload a File over http to SD Card with Timestamp from the original File. With sd.h a simple Upload is working. But the Timestamp is every time 1.1.2020 01:00

My Includes:

#include "SdFat.h"
#include "sdios.h"
#include <ESP8266WiFi.h>      
#include <ESP8266WiFiMulti.h> 
#include <ESP8266WebServer.h> 
#include <ESP8266HTTPClient.h>
#include <ESP8266mDNS.h>

My Old code with sd.h for download:

void SD_file_download(String filename){
  if (SD_present) { 
    File download = SD.open(filename);
    if (download) {
      filename.replace(" ","_"); 
      int last_slash = filename.lastIndexOf('/') + 1; 
      filename = filename.substring(last_slash); 
      server.sendHeader("Content-Type", "text/text");
      server.sendHeader("Content-Disposition", "attachment; filename="+filename);
      server.sendHeader("Connection", "close");
      server.streamFile(download, "application/octet-stream");
      download.close();
    } else del = "2"; 
  } else ReportSDNotPresent();
}

My new Code for Download with SdFat.h:

void SD_file_download(String filename){
SdFile dl_file;
  if (SD_present) { 
    if (dl_file.open(filename.c_str())) {
      filename.replace(" ","_"); 
      int last_slash = filename.lastIndexOf('/') + 1; 
      filename = filename.substring(last_slash); 
      server.sendHeader("Content-Type", "text/text");
      server.sendHeader("Content-Disposition", "attachment; filename="+filename);
      server.sendHeader("Connection", "close");
        size_t sent = server.streamFile(dl_file, "application/octet-stream");
      dl_file.close();
    } else del = "2";
  } else ReportSDNotPresent();
}

If i compile i get many errors

In file included from F:\Eigene Dateien\Arduino\esp_fileserver05\esp_fileserver05.ino:14:0:

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WebServer\src/ESP8266WebServer.h: In instantiation of 'size_t esp8266webserver::ESP8266WebServerTemplate<ServerType>::streamFile(T&, const String&, HTTPMethod) [with T = sdfat::SdFile; ServerType = WiFiServer; size_t = unsigned int]':

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WebServer\src/ESP8266WebServer.h:177:50:   required from 'size_t esp8266webserver::ESP8266WebServerTemplate<ServerType>::streamFile(T&, const String&) [with T = sdfat::SdFile; ServerType = WiFiServer; size_t = unsigned int]'

F:\Eigene Dateien\Arduino\esp_fileserver05\esp_fileserver05.ino:211:60:   required from here

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WebServer\src/ESP8266WebServer.h:185:58: error: 'class sdfat::SdFile' has no member named 'size'

 _streamFileCore(file.size(), file.name(), contentType);

                                                      ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WebServer\src/ESP8266WebServer.h:185:58: error: 'class sdfat::SdFile' has no member named 'name'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WebServer\src/ESP8266WebServer.h:187:21: error: no matching function for call to 'WiFiClient::write(sdfat::SdFile&)'

   contentLength = _currentClient.write(file);

                 ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WebServer\src/ESP8266WebServer.h:187:21: note: candidates are:

In file included from C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/ESP8266WiFi.h:39:0,

             from F:\Eigene Dateien\Arduino\esp_fileserver05\esp_fileserver05.ino:12:

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:59:18: note: virtual size_t WiFiClient::write(uint8_t)

virtual size_t write(uint8_t) override;

              ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:59:18: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'uint8_t {aka unsigned char}'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:60:18: note: virtual size_t WiFiClient::write(const uint8_t*, size_t)

virtual size_t write(const uint8_t *buf, size_t size) override;

              ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:60:18: note:   candidate expects 2 arguments, 1 provided

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:62:10: note: size_t WiFiClient::write(Stream&)

size_t write(Stream& stream);

      ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:62:10: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'Stream&'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:65:10: note: size_t WiFiClient::write(Stream&, size_t)

size_t write(Stream& stream, size_t unitSize) __attribute__ ((deprecated));

      ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\libraries\ESP8266WiFi\src/WiFiClient.h:65:10: note:   candidate expects 2 arguments, 1 provided

In file included from C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Stream.h:26:0,

             from C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/HardwareSerial.h:32,

             from C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Arduino.h:245,

             from sketch\esp_fileserver05.ino.cpp:1:

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:76:23: note: size_t Print::write(int8_t)

     inline size_t write(int8_t c) { return write((uint8_t) c); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:76:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'int8_t {aka signed char}'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:75:23: note: size_t Print::write(char)

     inline size_t write(char c) { return write((uint8_t) c); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:75:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'char'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:73:23: note: size_t Print::write(long unsigned int)

     inline size_t write(unsigned long t) { return write((uint8_t)t); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:73:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'long unsigned int'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:72:23: note: size_t Print::write(long int)

     inline size_t write(long t) { return write((uint8_t)t); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:72:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'long int'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:71:23: note: size_t Print::write(unsigned int)

     inline size_t write(unsigned int t) { return write((uint8_t)t); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:71:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'unsigned int'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:70:23: note: size_t Print::write(int)

     inline size_t write(int t) { return write((uint8_t)t); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:70:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'int'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:69:23: note: size_t Print::write(short unsigned int)

     inline size_t write(unsigned short t) { return write((uint8_t)t); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:69:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'short unsigned int'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:68:23: note: size_t Print::write(short int)

     inline size_t write(short t) { return write((uint8_t)t); }

                   ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:68:23: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'short int'

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:64:16: note: size_t Print::write(const char*, size_t)

     size_t write(const char *buffer, size_t size) {

            ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:64:16: note:   candidate expects 2 arguments, 1 provided

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:58:16: note: size_t Print::write(const char*)

     size_t write(const char *str) {

            ^

C:\Users\pl\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/Print.h:58:16: note:   no known conversion for argument 1 from 'sdfat::SdFile' to 'const char*'

exit status 1
Fehler beim Kompilieren für das Board LOLIN(WEMOS) D1 R2 & mini.

i can't use te line:File download = SD.open(filename); with sdfat.h because i get a compiler error "reference to 'File' is ambiguous"

The problem is this line: size_t sent = server.streamFile(file, "application/octet-stream");

How can i solve this problem?

Thank you for Help...

  • You got your naming backwards: “download” means “transfer from some remote host to the local system”, whereas “upload” is from the local system to a remote host. From the point of view of your sketch, the board it runs on (the Wemos) is the local system. The Windows PC is the remote host. – Edgar Bonet May 20 at 12:05
  • No, this is not the problem. With another library sd.h the download and upload works fine. But sd.h can not write timestamps to uploaded files. Therefore i must use the sdfat.h library. Upload means from pc to Wemos SD Card. Download means from Wemos SD Card to PC – Pascal May 20 at 14:05
  • Re “Upload means from pc to Wemos SD Card”: no, it doesn't, unless you are talking from the perspective of the PC (you are writing software for the PC). “Upload” means “send to the network”; “download” means “receive from the network”. Whatever your PC is uploading is a download on the Wemos. – Edgar Bonet May 20 at 14:42
  • you are right... if i see it from another perspective. But it does not solve the coding problem. – Pascal May 20 at 19:58
  • The ESP8266WebServer library is written to use SD.h. If you want it to use a different SD library you will have to re-write that library to use it. – Majenko May 20 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.