Hi,
Have been trying this now for some time.
I am uploading JPG files to server, However they loose characters and sometimes the file is larger.
Using standard arduino FTP with check for buffer and pins added but no change.
File fh;
byte doFTP()
{
#ifdef FTPWRITE
fh = SD.open(JPG_Filename,FILE_READ);
#else
SD.remove(JPG_Filename);
fh = SD.open(JPG_Filename,FILE_WRITE);
#endif
if(!fh)
{
Serial.println(F("SD open fail"));
return 0;
}
#ifndef FTPWRITE
if(!fh.seek(0))
{
Serial.println(F("Rewind fail"));
fh.close();
return 0;
}
#endif
Serial.println(F("SD opened"));
if (client.connect(server,21)) {
Serial.println(F("Command connected"));
}
else {
fh.close();
Serial.println(F("Command connection failed"));
return 0;
}
if(!eRcv()) return 0;
client.println(F("USER xxxxx"));
if(!eRcv()) return 0;
client.println(F("PASS xxxxx"));
if(!eRcv()) return 0;
client.println(F("SYST"));
if(!eRcv()) return 0;
client.println(F("PASV"));
if(!eRcv()) return 0;
char *tStr = strtok(outBuf,"(,");
int array_pasv[6];
for ( int i = 0; i < 6; i++) {
tStr = strtok(NULL,"(,");
array_pasv[i] = atoi(tStr);
if(tStr == NULL)
{
Serial.println(F("Bad PASV Answer"));
}
}
client.println(F("CWD public_html"));
if(!eRcv()) return 0;
unsigned int hiPort,loPort;
hiPort = array_pasv[4] << 8;
loPort = array_pasv[5] & 255;
Serial.print(F("Data port: "));
hiPort = hiPort | loPort;
Serial.println(hiPort);
if (dclient.connect(server,hiPort)) {
Serial.println(F("Data connected"));
}
else {
Serial.println(F("Data connection failed"));
client.stop();
fh.close();
return 0;
}
#ifdef FTPWRITE
client.print(F("STOR "));
client.println(JPG_Filename);
#else
client.print(F("RETR "));
client.println(JPG_Filename);
#endif
if(!eRcv())
{
dclient.stop();
return 0;
}
#ifdef FTPWRITE
Serial.println(F("Writing"));
byte clientBuf[64];
int clientCount = 0;
/*
while(fh.available())
{
clientBuf[clientCount] = fh.read();
clientCount++;
if(clientCount > 63)
{
dclient.write(clientBuf,64);
clientCount = 0;
}
}
*/
[b]int newFree = client.free();
Serial.print("Free Buffer:");
Serial.println(newFree, DEC);
while(fh.available())
{
digitalWrite(10,HIGH);
//digitalWrite(4,LOW);
clientCount = fh.read(clientBuf,32);
//digitalWrite(10,LOW);
digitalWrite(4,HIGH);
newFree = client.free();
if(newFree < 250)
{
Serial.print("Low buffer ");
Serial.println(newFree, DEC);
}
dclient.write(clientBuf,clientCount);
int icount = 0;
while (icount < clientCount)
{
if(clientBuf[icount]<0x10) Serial.print("0");
Serial.print(clientBuf[icount++],HEX);
Serial.print(" ");
}
Serial.println();
newFree = client.free();
Serial.print("Free Buffer:");
Serial.println(newFree, DEC);
delay(50);
}[/b]
if(clientCount > 0) dclient.write(clientBuf,clientCount);
#else
while(dclient.connected())
{
while(dclient.available())
{
char c = dclient.read();
fh.write(c);
Serial.write(c);
}
}
#endif
dclient.stop();
Serial.println(F("Data disconnected"));
if(!eRcv()) return 0;
client.println(F("QUIT"));
if(!eRcv()) return 0;
client.stop();
Serial.println(F("Command disconnected"));
fh.close();
Serial.println(F("SD closed"));
return 1;
}
the correct data comes from the SD card when printed out but the received file is loosing characters.
have highlighted code area problem.
Using atmega 2560 and Ethernet shield.
any pointers to tracking the problem would be appreciated. I am connecting over wireless from switch. But the data loss is too consistent to be wireless issue. And I can download anything from Filezilla.
Have tried connecting to local PC Filezilla for testing but unsuccessful yet. Can connect to web with no problem except for missing characters around 155 bytes in.
Have changed buffer sizes to no avail.
Any suggestion welcome?
thanks
albert