From f83e41da5a0d265d8cf250292a546b47556c9e63 Mon Sep 17 00:00:00 2001 From: theFeiter Date: Sat, 23 Jul 2022 18:30:44 +0200 Subject: [PATCH] add SD support --- FDRS_Gateway/fdrs_functions.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/FDRS_Gateway/fdrs_functions.h b/FDRS_Gateway/fdrs_functions.h index ee4457f..04be4ed 100644 --- a/FDRS_Gateway/fdrs_functions.h +++ b/FDRS_Gateway/fdrs_functions.h @@ -294,10 +294,23 @@ void mqtt_callback(char* topic, byte * message, unsigned int length) { void resendLog(){ #ifdef USE_SD_LOG - /*DBG("Releasing Log buffer to SD"); - File logfile = SD.open(SD_FILENAME, FILE_WRITE); - logfile.print(logBuffer); - logfile.close();*/ + DBG("Resending logged values from SD card."); + File logfile = SD.open(SD_FILENAME, FILE_READ); + while(1){ + String line = logfile.readStringUntil('\n'); + if (line.length() > 0){ // if line contains something + if (!client.publish(TOPIC_DATA, line.c_str())) { + break; + }else{ + time(&last_mqtt_success); + } + }else{ + logfile.close(); + SD.remove(SD_FILENAME); // if all values are sent + break; + } + } + DBG(" Done"); #endif #ifdef USE_FS_LOG DBG("Resending logged values from internal flash."); @@ -311,11 +324,11 @@ void resendLog(){ time(&last_mqtt_success); } }else{ + logfile.close(); LittleFS.remove(FS_FILENAME); // if all values are sent break; } } - logfile.close(); DBG(" Done"); #endif