Hello, everyone. Need help
How do I add lines to CSV files on external FTP server?
Libraries I use:
SDFat
FTP
BufferStream
if (ftp.connect(FTPserver, user3, pass3)) {
Serial.println("Connecting to FTP server");
initSdFile();
csv.gotoBeginOfFile();
csvTarget.gotoBeginOfFile();
const byte BUFFER_SIZE = 5;
char buffer[BUFFER_SIZE + 1];
String bff ;
buffer[BUFFER_SIZE] = '\0';
char data[1000];
WriteBufferStream stream(data, 1000);
do
{
do
{
while (csv.readField(buffer, BUFFER_SIZE))
{
bff = bff + buffer;
}
bff = bff + ";";
}
while (csv.nextField() );
Serial.println(bff);
stream.print(bff);
bff = "";
stream.write("\n");
}
while (csv.nextLine() );
stream.write(uint8_t('\0'));
ftp.store(FILENAME, stream);
Serial.println("File ended");
Serial.println(data);
csv.close();
}
Code I attached does everything except the last bit. I successfully read the file field by field and store it in a data array, data array shows what it supposed to be in a monitor, even the file is created on an FTP server, but the content is empty.
github page of FTP lib states that I can use stream created with StreamBuffer lib, am I using it correctly?
I tried to outsmart the code and substituted
ftp.store(FILENAME, stream);
with
Serial2.println(data);
ftp.store(FILENAME, Serial3);
by adding a jumper from TX2 to RX3 and it worked, but only stored 1st 40 characters or so (which I assume due to Serial buffer limitations). Doing the same jumper trick but moving the store command 1 loop deeper (every line as oppose to in the end of the file) trying to store every line also works, but it seems to rewrite the line and I always end up with only the last line (Serial2 prints bff instead).
FTP lib states, that the 2nd argument supposed to be a stream and I have little to no experience with it
Please, help, keep starring at the monitor with no clue