Chat freely about anything...

User avatar
By Sirquil
#81114 Thank you martinayotte for your readFile function for ESP8266.

Is there a reason it drops characters; when used with ESP32. No matter the file, this is happening.

Here is file downloaded with Filezilla:

Code: Select allStarted Server:  RTC  2019/03/10 00:25:59 UTC
Started Server:  RTC  2019/03/10 00:26:17 UTC
Started Server:  RTC  2019/03/10 01:39:26 UTC
Started Server:  RTC  2019/03/10 01:39:45 UTC
Started Server:  RTC  2019/03/10 05:26:02 UTC
Started Server:  RTC  2019/03/10 05:26:23 UTC
Started Server:  RTC  2019/03/10 14:00:46 UTC
Started Server:  RTC  2019/03/10 14:01:20 UTC
Started Server:  RTC  2019/03/10 15:40:58 UTC
Started Server:  RTC  2019/03/10 15:45:11 UTC
Started Server:  RTC  2019/03/10 15:47:37 UTC
Started Server:  RTC  2019/03/10 15:49:43 UTC
Started Server:  RTC  2019/03/11 15:02:11 UTC
Started Server:  RTC  2019/03/11 14:59:28 UTC
Started Server:  RTC  2019/03/11 15:04:51 UTC
Started Server:  RTC  2019/03/13 20:16:38 UTC
Started Server:  RTC  2019/03/13 20:23:21 UTC
Started Server:  RTC  2019/03/13 20:28:14 UTC
Started Server:  RTC  2019/03/13 20:28:56 UTC
Started Server:  RTC  2019/03/13 20:29:56 UTC
Started Server:  RTC  2019/03/13 20:30:25 UTC
Started Server:  RTC  2019/03/13 20:32:36 UTC
Started Server:  RTC  2019/03/13 20:33:31 UTC
Started Server:  RTC  2019/03/13 20:34:24 UTC
Started Server:  RTC  2019/03/13 20:37:50 UTC
Started Server:  RTC  2019/03/13 20:38:07 UTC
Started Server:  RTC  2019/03/13 20:38:30 UTC
Started Server:  RTC  2019/03/13 20:41:31 UTC
Started Server:  RTC  2019/03/13 22:10:51 UTC
Started Server:  RTC  2019/03/13 22:23:21 UTC
Started Server:  RTC  2019/03/13 22:26:17 UTC
Started Server:  RTC  2019/03/13 22:26:47 UTC
Started Server:  RTC  2019/03/14 04:31:05 UTC
Started Server:  RTC  2019/03/14 18:11:23 UTC


File downloaded with SdBrowse function, that uses readFile function:

[code]Started Server:  RTC  2019/03/10 00:25:59 UTC
Started Server:  RTC  2019/03/10 00:26:17 UTC
Started Server:  RTC  2019/03/10 01:39:26 UTC
Started Server:  RTC  2019/03/10 01:39:45 UTC
Started Server:  RTC  2019/03/10 05:26:02 UTC
Started Server:  RTC  2019/03/10 05:26:23 UTC
Started Server:  RTC  2019/03/10 14:00:46 UTC
Started Server:  RTC  2019/03/10 14:01:20 UTC
Started Server:  RTC  2019/03/10 15:40:58 UTC
Started Server:  RTC  2019/03/10 15:45:11 UTC
Started Server:  RTC  2019/03/10 15:47:37 UTC
Started Server:  RTC  2019/03/10 15:49:43 UTC
Started Server:  RTC  2019/03/11 15:02:11 UTC
Started Server:  RTC  2019/03/11 14:59:28 UTC
Started Server:  RTC  2019/03/11 15:04:51 UTC
Started Server:  RTC  2019/03/13 20:16:38 UTC
Started Server:  RTC  2019/03/13 20:23:21 UTC
Started Server:  RTC  2019/03/13 20:28:14 UTC
Started Server:  RTC  2019/03/13 20:28:56 UTC
Started Server:  RTC  2019/03/13 20:29:56 UTC
Started Server:  RTC  2019/03/13 20:30:25 UTC
Started Server:  RTC  2019/03/13 20:32:36 UTC
Started Server:  RTC  2019/03/13 20:33:31 UTC
Started Server:  RTC  2019/03/13 20:34:24 UTC
Started Server:  RTC  2019/03/13 20:37:50 UTC
Started Server:  RTC  2019/03/13 20:38:07 UTC
Started Server:  RTC  2019/03/13 20:38:30 UTC
Started Server:  RTC  2019/03/13 20:41:31 UTC
Started Server:  RTC  2019/03/13 22:10:51 UTC
Started Server:  RTC  2019/03/13 22:23:21 UTC
Started Server:  RTC  2019/03/13 22:26:17 UTC
Started Server:  RTC  2019/03/13 22:26:47 UTC
Started Server:  RTC  2019/03/14 04:31:05 UTC
Started Server:  RTC  2019/03/14 18:11:23 UTC
ver:  RTC  2019/03/11 15:02:11 UTC
Started Server:  RTC  2019/03/11 14:59:28 UTC
Started Server:  RTC  2019/03/11 15:04:51 UTC
Started Server:  RTC  2019/03/13 20:16:38 UTC
Started Server:  RTC  2019/03/13 20:23:21 UTC
Started Server:  RTC  2019/03/13 20:28:14 UTC
Started Server:  RTC  2019/03/13 20:28:56 UTC
Started Server:  RTC  2019/03/13 20:29:56 UTC
Started Server:  RTC  2019/03/13 20:30:25 UTC
Started Server:  RTC  2019/03/13 20:[/code]

readFile function:

[code]void readFile()
{

//     digitalWrite(online, HIGH);   //turn-on online LED indicator

     String filename = (const char *)&MyBuffer;

     Serial.print("File:  ");
     Serial.println(filename);


     File webFile = SPIFFS.open(filename);

     if (!webFile)
     {
          Serial.println("File" + filename + "failed to open");
          Serial.println("\n");
     }
     else
     {
          char buf[1024];
          int siz = webFile.size();
          //.setContentLength(str.length() + siz);
          //webserver.send(200, "text/plain", str);
          while (siz > 0)
          {
               size_t len = std::min((int)(sizeof(buf) - 1), siz);
               while(webFile.available())
               {
                   webFile.read((uint8_t *)buf, len);
                   client.write((const char*)buf, len);
                   siz -= len;
               }
          }
         
          delay(500);
      
      webFile.flush();
         
          webFile.close();
     
     }

     error = 0;

     delayTime = 1000;

     MyBuffer[0] = '\0';

//     digitalWrite(online, LOW);   //turn-off online LED indicator

     listen();
}



Tried adding a delay before closing webFile and flushing webFile; both produced no change in output.

readFile function works perfectly with the ESP8266.

William
Last edited by Sirquil on Fri Mar 22, 2019 1:10 pm, edited 1 time in total.
User avatar
By RichardS
#81115 Try making char buf[1024] into char buf[32]

The serial printing may not like the long print....

RichardS
User avatar
By RichardS
#81116 Could also be done:

Code: Select allchar buf[32];
int len;
 while  (len = webFile.read(buf, 32)) {
   client.write((const char*)buf, len);
 }


RichardS
User avatar
By Sirquil
#81118
Try making char buf[1024] into char buf[32]

The serial printing may not like the long print....

RichardS


Still drops characters with char buf[32].

Code: Select allchar buf[32];
int len;
 while  (len = webFile.read(buf, 32)) {
   client.write((const char*)buf, len);
 }


Produces compiler error: invalid conversion from 'char*' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

Thank you for the suggestions.

William