Browse Source

Removed SD not mandatory + mem-improvements

master
Torsten Stauder 5 years ago
parent
commit
eab888e227
  1. 4
      src/logmessages.h
  2. 4
      src/logmessages_EN.h
  3. 35
      src/main.cpp
  4. 7
      src/settings.h

4
src/logmessages.h

@ -155,3 +155,7 @@ static const char failedOpenFileForWrite[] PROGMEM = "Öffnen der Datei für den
static const char fileWritten[] PROGMEM = "Schreibe Datei";
static const char writeFailed[] PROGMEM = "Schreibvorgang fehlgeschlagen";
static const char writingFile[] PROGMEM = "Schreibe Datei";
static const char failedToOpenFileForAppending[] PROGMEM = "Öffnen der Datei zum Schreiben der JSON-Datei fehlgeschlagen";
static const char listingDirectory[] PROGMEM = "Verzeichnisinhalt anzeigen";
static const char failedToOpenDirectory[] PROGMEM = "Öffnen des Verzeichnisses fehlgeschlagen";
static const char notADirectory[] PROGMEM = "Kein Verzeichnis";

4
src/logmessages_EN.h

@ -155,3 +155,7 @@ static const char failedOpenFileForWrite[] PROGMEM = "Failed to open file for wr
static const char fileWritten[] PROGMEM = "File written";
static const char writeFailed[] PROGMEM = "Write failed";
static const char writingFile[] PROGMEM = "Writing file";
static const char failedToOpenFileForAppending[] PROGMEM = "Failed to open file for appending";
static const char listingDirectory[] PROGMEM = "Listing directory";
static const char failedToOpenDirectory[] PROGMEM = "Failed to open directory";
static const char notADirectory[] PROGMEM = "Not a directory";

35
src/main.cpp

@ -310,9 +310,7 @@ void buttonHandler();
void deepSleepManager(void);
void doButtonActions(void);
void doRfidCardModifications(const uint32_t mod);
#ifndef SD_NOT_MANDATORY_ENABLE
bool dumpNvsToSd(char *_namespace, char *_destFile);
#endif
bool dumpNvsToSd(char *_namespace, char *_destFile);
bool endsWith (const char *str, const char *suf);
bool fileValid(const char *_fileItem);
void freeMultiCharArray(char **arr, const uint32_t cnt);
@ -476,13 +474,13 @@ bool isFirstJSONtNode = true;
*/
void appendNodeToJSONFile(fs::FS &fs, const char * path, const char *filename, const char *parent, const char *type ) {
// Serial.printf("Appending to file: %s\n", path);
snprintf(logBuf, serialLoglength, "Listing directory: %s\n", filename);
snprintf(logBuf, serialLoglength, "%s: %s\n", (char *) FPSTR(listingDirectory), filename);
loggerNl(logBuf, LOGLEVEL_DEBUG);
File file = fs.open(path, FILE_APPEND);
// i/o is timing critical keep all stuff running
esp_task_wdt_reset();
if (!file) {
snprintf(logBuf, serialLoglength, "Failed to open file for appending");
snprintf(logBuf, serialLoglength, (char *) FPSTR(failedToOpenFileForAppending));
loggerNl(logBuf, LOGLEVEL_DEBUG);
return;
}
@ -534,7 +532,8 @@ bool pathValid(const char *_fileItem) {
* @param parent
* @param levels
*/
char fileNameBuf[255];
//char fileNameBuf[255];
char *fileNameBuf = (char *) calloc(255, sizeof(char)); // In heap to save static memory
void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint8_t levels) {
esp_task_wdt_reset();
@ -543,13 +542,13 @@ void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint
File root = fs.open(dirname);
if (!root) {
snprintf(logBuf, serialLoglength, "Failed to open directory");
snprintf(logBuf, serialLoglength, (char *) FPSTR(failedToOpenDirectory));
loggerNl(logBuf, LOGLEVEL_DEBUG);
return;
}
if (!root.isDirectory()) {
snprintf(logBuf, serialLoglength, "Not a directory");
snprintf(logBuf, serialLoglength, (char *) FPSTR(notADirectory));
loggerNl(logBuf, LOGLEVEL_DEBUG);
return;
}
@ -568,7 +567,7 @@ void parseSDFileList(fs::FS &fs, const char * dirname, const char * parent, uint
continue;
}
strncpy(fileNameBuf, (char *) file.name(), sizeof(fileNameBuf) / sizeof(fileNameBuf[0]));
strncpy(fileNameBuf, (char *) file.name(), 255);
// we have a folder
if(file.isDirectory()) {
@ -3163,9 +3162,7 @@ bool processJsonRequest(char *_serialJson) {
if (s.compareTo(rfidString)) {
return false;
}
#ifndef SD_NOT_MANDATORY_ENABLE
dumpNvsToSd("rfidTags", (char *) FPSTR(backupFile)); // Store backup-file every time when a new rfid-tag is programmed
#endif
} else if (doc.containsKey("rfidAssign")) {
const char *_rfidIdAssinId = object["rfidAssign"]["rfidIdMusic"];
@ -3181,9 +3178,7 @@ bool processJsonRequest(char *_serialJson) {
if (s.compareTo(rfidString)) {
return false;
}
#ifndef SD_NOT_MANDATORY_ENABLE
dumpNvsToSd("rfidTags", (char *) FPSTR(backupFile)); // Store backup-file every time when a new rfid-tag is programmed
#endif
} else if (doc.containsKey("wifiConfig")) {
const char *_ssid = object["wifiConfig"]["ssid"];
@ -3221,7 +3216,7 @@ bool processJsonRequest(char *_serialJson) {
return true;
}
char *jBuf = (char *) calloc(255, sizeof(char)); // In heap to save static memory
// Sends JSON-answers via websocket
void sendWebsocketData(uint32_t client, uint8_t code) {
const size_t CAPACITY = JSON_OBJECT_SIZE(1) + 20;
@ -3242,8 +3237,9 @@ void sendWebsocketData(uint32_t client, uint8_t code) {
object["indexingState"] = fileNameBuf;
}
char jBuf[255];
serializeJson(doc, jBuf, sizeof(jBuf) / sizeof(jBuf[0]));
//char jBuf[255];
serializeJson(doc, jBuf, 255);
if (client == 0) {
ws.printfAll(jBuf);
@ -3376,7 +3372,7 @@ void webserverStart(void) {
});
wServer.on("/files", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SD, "/files.json", "application/json");
request->send(SD, DIRECTORY_INDEX_FILE, "application/json");
});
wServer.onNotFound(notFound);
@ -3390,7 +3386,6 @@ void webserverStart(void) {
// Dumps all RFID-entries from NVS into a file on SD-card
#ifndef SD_NOT_MANDATORY_ENABLE
bool dumpNvsToSd(char *_namespace, char *_destFile) {
esp_partition_iterator_t pi; // Iterator for find
const esp_partition_t* nvs; // Pointer to partition struct
@ -3454,7 +3449,6 @@ void webserverStart(void) {
backupFile.close();
return true;
}
#endif
// Handles uploaded backup-file and writes valid entries into NVS
@ -3559,9 +3553,6 @@ void setup() {
#endif
loggerNl((char *) FPSTR(unableToMountSd), LOGLEVEL_ERROR);
delay(500);
#ifdef SD_NOT_MANDATORY_ENABLE
break;
#endif
#ifdef SHUTDOWN_IF_SD_BOOT_FAILS
if (millis() >= deepsleepTimeAfterBootFails*1000) {
loggerNl((char *) FPSTR(sdBootFailedDeepsleep), LOGLEVEL_ERROR);

7
src/settings.h

@ -13,7 +13,6 @@
//#define PLAY_LAST_RFID_AFTER_REBOOT // When restarting Tonuino, the last RFID that was active before, is recalled and played
//#define SINGLE_SPI_ENABLE // If only one SPI-instance should be used instead of two (not yet working!)
//#define SD_NOT_MANDATORY_ENABLE // Only for debugging-purposes: Tonuino will also start without mounted SD-card anyway (will only try once to mount it). Will overwrite SHUTDOWN_IF_SD_BOOT_FAILS!
//#define BLUETOOTH_ENABLE // Doesn't work currently (so don't enable) as there's not enough DRAM available
@ -97,9 +96,7 @@ uint16_t intervalToLongPress = 700; // Interval in ms to disting
static const char accessPointNetworkSSID[] PROGMEM = "Tonuino"; // Access-point's SSID
// Where to store the backup-file for NVS-records
#ifndef SD_NOT_MANDATORY_ENABLE
static const char backupFile[] PROGMEM = "/backup.txt"; // File is written every time a (new) RFID-assignment via GUI is done
#endif
static const char backupFile[] PROGMEM = "/backup.txt"; // File is written every time a (new) RFID-assignment via GUI is done
// (webgui) File Browser
uint8_t FS_DEPTH = 5; // Max. recursion-depth of file tree
@ -152,5 +149,7 @@ float voltageIndicatorHigh = 4.2; // Upper range for Neopixel-
static const char topicRepeatModeState[] PROGMEM = "State/Tonuino/RepeatMode";
static const char topicLedBrightnessCmnd[] PROGMEM = "Cmnd/Tonuino/LedBrightness";
static const char topicLedBrightnessState[] PROGMEM = "State/Tonuino/LedBrightness";
#ifdef MEASURE_BATTERY_VOLTAGE
static const char topicBatteryVoltage[] PROGMEM = "State/Tonuino/Voltage";
#endif
#endif
Loading…
Cancel
Save