Iām compiling the sd fat library that we can get on github for particle photon.
The problem is not related to the writing part but with the TCPClient itself or ftp program. I have exactly the same issue with SPIFFS and the SPI flashā¦ so itās not related to the Sd card library.
If you look at the debug info below itās leaving the while loop and if according to wireshark, all the data is sent correctly so it look like the TCPClient is dropping the connection while there is still bytes available.
[2] 220 Welcome to FTPino FTP Server.
[2] USER sam
[2] 331 Password required for user sam.
[2] PASS (hidden)
[2] 230 User successfuly logged in.
[2] SYST
[2] 215 UNIX emulated by FTPino.
[2] TYPE A
[2] 200 Type set to BINARY.
[2] REST 1
[2] 350 Restarting at 1. !!! Not implemented
[2] REST 0
[2] 350 Restarting at 0. !!! Not implemented
[2] FEAT
[2] 211 Extensions supported SIZE MDTM XCRC.
[2] PWD
[2] 257 "/" is current directory.
[2] CWD /
[2] 250 "//" is current directory.
[2] PWD
[2] 257 "/" is current directory.
[2] PASV
[2] 227 Entering Passive Mode (192,168,2,155,4,0)
[2] Ouverture de la connexion IP: 192.168.2.155 PORT: 1024
[2] LIST
[2] 150 Opening ASCII mode data connection for transfer.
[2] 226 Transfer complete.
[2] Liste Complete: 572 bytes en 0,00s (0,57KB/s)
[2] TYPE I
[2] 200 Type set to BINARY.
[2] PASV
[2] 227 Entering Passive Mode (192,168,2,155,4,0)
[2] Ouverture de la connexion IP: 192.168.2.155 PORT: 1024
[2] REST 0
[2] 350 Restarting at 0. !!! Not implemented
[2] STOR oil-rtestsam.bmp
[2] 150 Opening BINARY mode data connection for file transfer.
[2] 226 Transfer complete. 4736 bytes written.
[2] MDTM 20160714194300 oil-rtestsam.bmp
[2] 502 Command not implemented: MDTM 20160714194300 oil-rtestsam.bmp.
[i] oil-rtestsam.bmp 8,5 kbytes/0,25(s)/32,77Kbps
[i] 1 fichier(s) transfere(s) - Total: 8,5 k byte(s) en 0,25 (32,77 KBps)
This is the code:
int bytesRead =0;
do
{
bytesRead = dclient.read(readBuffer, sizeof(readBuffer));
if(bytesRead > 0)
{
dbg("Bytes read:", String(bytesRead));
dbg("Client available:", String(dclient.available()));
maxIterations = 2000;
fh->writeFile(file, reinterpret_cast<char*>(readBuffer), bytesRead, isAppend);
totalBytes+= bytesRead, bytesRead = 0;
}
Particle.process();
maxIterations--;
dbg("Client connected:", String(dclient.connected()));
}while(( dclient.connected() || dclient.available()) ||
(isFTPinoClient && (maxIterations > 0)));
dbg("Client connected:", String(dclient.connected()));
dbg("Client available:", String(dclient.available()));
dbg("IsFTPinoClient:", String(isFTPinoClient ? 1 : 0));
dbg("Iterations:", String(maxIterations));
And here is the serial debug trace:
Bytes read:->128
Client available:->128
Client connected:->1
Bytes read:->128
Client available:->128
Client connected:->1
Bytes read:->128
Client available:->0
Client connected:->0
Client connected:->0
Client available:->0
IsFTPinoClient:->0
Iterations:->1999