Greetings, my name is Faishal. I'm new to this forum. So, pardon me if I made this in the wrong section or made other noobly mistakes.
intro
I'm currently working on a project of creating a device to monitor Indoor Air Quality. This project was supposed to be an IoT-based in regards to datalogging the measured data. So I use ESP8266 (Wemos D1 Mini board) as the board of choice. I've got all things sorted out and sucessfully made the device. Sadly, the project had kind of skewed (re-purposed) to not having an "IoT properties". By that, the datalogging should be done into an SD Card.
problem
Rather than using another board for the device, I still have to use Wemos D1 Mini since I have made the custom PCB and the 3D printed enclosure for the device specifically for the board. So I bought a Wemos D1 Mini datalogger shield which contain DS1307 RTC Chip and a micro SD Card reader/writer. I was able to make the RTC work and able to make the board to create a file (datalog.txt) to datalog into. However, the board is not able to write any lines of data to the file BUT the last line.
I tried to troubleshoot by making a file (with the same name as coded into the board;datalog.txt) using my computer and wrote a random word in the first line of the file. By this, the first line of the datalog.txt should've been the random word even after I let the board to write into the file. However, after I let the board datalog, the random word is not there anymore and seems to be overwritten by the last line that the board write (or the whole file is overwritten).
Refering to Arduino's SD.Open syntax explanation, the
</sup></sub> <sub><sup>FILE_WRITE</sup></sub> <sub><sup>
argument suppose to do "reading and writing, starting at EOF". In this case, it seems that it haven't.
So, how can I assess this situation ?
I've been searching to a lot of sites, asking friends, and haven't found the solution. Please, help
I'm using [tt][sub][sup]SD.h[/sup][/sub]
[/tt] library and below are fragments of my code.
void printToSD()
{
File KitPlane = SD.open("datalog.txt", FILE_WRITE);
//delay(5000);
now = Rtc.GetDateTime();
if (KitPlane)
{
KitPlane.print("[MM/DD/YYYY hh:mm:ss - CO2 RH T O2 TVOC PM2.5]");
KitPlane.print(",");
KitPlane.print(now.Month(), DEC);
KitPlane.print("/");
KitPlane.print(now.Day(), DEC);
KitPlane.print("/");
KitPlane.print(now.Year(), DEC);
KitPlane.print(" ");
KitPlane.print(now.Hour(), DEC);
KitPlane.print(":");
KitPlane.print(now.Minute(), DEC);
KitPlane.print(":");
KitPlane.print(now.Second(), DEC);
KitPlane.print(",");
KitPlane.print(F_CO2);
KitPlane.print(",");
KitPlane.print(F_RH);
KitPlane.print(",");
KitPlane.print(F_Temp);
KitPlane.print(",");
KitPlane.print(F_O2);
KitPlane.print(",");
KitPlane.print(F_TVOC);
KitPlane.print(",");
KitPlane.print(F_PM);
KitPlane.println(",");
Serial.print("[MM/DD/YYYY hh:mm:ss - CO2 RH T O2 TVOC PM2.5]");
Serial.print(",");
Serial.print(now.Month(), DEC);
Serial.print("/");
Serial.print(now.Day(), DEC);
Serial.print("/");
Serial.print(now.Year(), DEC);
Serial.print(" ");
Serial.print(now.Hour(), DEC);
Serial.print(":");
Serial.print(now.Minute(), DEC);
Serial.print(":");
Serial.print(now.Second(), DEC);
Serial.print(",");
Serial.print("[MM/DD/YYYY HH:MM:SS CO2 RH T O2 TVOC PM2.5],");
Serial.print(",");
Serial.print(F_CO2);
Serial.print(",");
Serial.print(F_RH);
Serial.print(",");
Serial.print(F_Temp);
Serial.print(",");
Serial.print(F_O2);
Serial.print(",");
Serial.print(F_TVOC);
Serial.print(",");
Serial.println(F_PM);
}
else {
Serial.println("DataLogging-ERROR");
}
KitPlane.close();
delay(5000);
}
TL;DR :
My setup can't seem to "append" a line of string into an existing file in an SD Card. It rather overwrite or make a new file with only one line inside (the last line written). How to assess ?
Thank you
Best regards,
Faishal