Skip to content

SD Card reading --> ESP32 freezes (connection to server/WLAN gets lost) #6846

Closed
@basementmedia2

Description

@basementmedia2

Board

ESP32 (Wemos D1 mini)

Device Description

Custom ESP32, got no photo here sorry (am in the office right now)

Hardware Configuration

SD-Card Shield connected

Version

v2.0.3

IDE Name

Arduino IDE

Operating System

Linux Manjaro

Flash frequency

40

PSRAM enabled

no

Upload speed

115200

Description

I have a sketch which works as follows:

On client-side (webserver) the user selects a date which is then sent (per Ajax) to the ESP.
if the date is e.g. "2022-06-08" a file named "2022-06-08.bin" is opened for reading and then read line by line.

With esp core 1.0.6 it works perfectly.
Same code with esp core 2.0.2 was very slow (cause there was still a bug i think)
Now with esp core 2.0.3 it is really fast again, but after a few date selects (means a few SD-card-Read-cycles) the esp totally freezes (webserver is not available any more).

Sketch

// Just Parts of the Sketch
// I cannot publish complete Sketch here because of copyrights (customer project)

struct data {
  uint16_t value1;
  uint16_t value2;
  uint16_t value3;
  // 10 more values, just an example 
};

void tagesauswertung (char* datum_select, int startpos, int endpos, int tag, int monat, int jahr, int rand_key_sent) {
  struct data Messung;
  DynamicJsonDocument auswertung_arr(4800);

  sprintf(filename_auswertung, "/e/%s.bin", datum_select);
  auswertungenFile = SD.open(filename_auswertung, FILE_READ);
  if (auswertungenFile) {
    
    int i = 0;
    int alive = 0;
    while (auswertungenFile.available()) {

      auswertungenFile.read((uint8_t *)&Messung, sizeof(Messung));
      
      if (i >= startpos && i <= endpos) {
        // As the file is very big, the JSON-Array would get to o big
        // So the server sends "startpos" and "endpos" and thus the content is transferred partly to the client
        alive = 1;
        auswertung_arr[i - startpos]["val1"] = Messung.value1;
        auswertung_arr[i - startpos]["val2"] = Messung.value2;
        auswertung_arr[i - startpos]["val3"] = Messung.value3;
        // ten more values, just an example
      }
      i++;
    }

    if (alive == 1) {
      // Still Data left --> Send it to the client
      String jsonString;
      serializeJson(auswertung_arr, jsonString);
      Serial.println(jsonString);
      server.send(200, "application/json", jsonString);
    } else {
        server.send(200, "text/plain", "Done");
    }

  } else {
    server.send(200, "text/plain", "Fehler");
  } 
}

Debug Message

ESP Freezes (Webserver is not available anymore)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Area: LibrariesIssue is related to Library support.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions