Problem in transfering a jpg file to FTP server using the GPRS model Quectel M10

I am trying to transfer jpg file from SD card to a FTP server using Quectel M10 via GPRS.
here is some reference materials:
Quectel_M10_AT_Commands_Manual?http://www.quectel.com/product/prodetail.aspx?id=14
Quectel_M10_datasheet?http://arduino.cc/en/Main/ArduinoGSMShield
and attached files: GSM FTP AT Commands.pdf
also I have used the code here as my reference?http://www.cooking-hacks.com/documentation/tutorials/arduino-3g-gprs-gsm-gps#step13

My code segment about the at commands:

void loop()
{
    //sendATcommand("AT", "OK", 5000);
    power_on();
    Serial.println("GSM modem working!");
    delay(3000);

    // waits for signal
    while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
            sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );
    // sets APN, user name and password
    answer=sendATcommand("AT+QIFGCNT=0","OK",1000);
    Serial.println(answer);
    answer=sendATcommand("AT+QICSGP=1,\"CMNET\"","OK",1000);
    Serial.println(answer);
    answer=sendATcommand("AT+QFTPUSER=\"admin\"","OK",3000);
    Serial.println(answer);
    answer=sendATcommand("AT+QFTPPASS=\"admin\"","OK",3000);
    Serial.println(answer);
    // sets the paremeters for the FTP server and the path
    answer=sendATcommand("AT+QFTPOPEN=\"xx.xx.xx.xx\",21","+QFTPOPEN:0",120000);
    Serial.println(answer);
    answer=sendATcommand("AT+QFTPPATH=\"/\"","+QFTPPATH:0",120000);
    Serial.println(answer);
    sprintf(strtemp, "AT+QFTPPUT=\"%s\",%d,600", filename,filelength);
    sprintf(answertemp,"+QFTPPUT:%d",filelength);
    answer = sendATcommand(strtemp, answertemp, 900000);

    Serial.println("send data to buff");
    while(mFile.position()<filelength)
    {
        for(int i=0; i<3; i++)
        {
            mFile.read(filedata,1024);
            for(int j=0; j<sizeof(filedata); j++)
            {
                Serial.println(filedata[j],HEX);           // observe the image data through serial port
                mySerial.write(filedata[j]);
            }
        }
        delayMicroseconds(1000);
    }
    mFile.close();
}

and this is the infomation I get from the Serial Monitor.
(13266 is the length of the jpg file.)

Initializing SD card...card initialized.
2.jpg is opened successful.
13266
AT
OK
1
GSM modem working!
AT+CREG?
+CREG: 0,1
AT+QIFGCNT=0
OK
1
AT+QICSGP=1,"CMNET"
OK
1
AT+QFTPUSER="admin"
OK
1
AT+QFTPPASS="admin"
OK
1
AT+QFTPOPEN="xx.xx.xx.xx",21
OK

+QFTPOPEN:0
1
AT+QFTPPATH="/"
OK

+QFTPPATH:0
1
AT+QFTPPUT="2.jpg",13266,600
+QFTPPUT:13266
AT+QFTPPUT="2.jpg",13266,600
OK

CONNECT
1
send data to buff
FF
D8
FF
E0
0
10
4A
46
49
46
0
1
1
1
0
60
0
60
.
.
.
.
.
.

Problem:
I get the data in the ftp server,not all the hex data of picture is right, the beginning about 10k byte data is right, the else is wrong.
Is the data send too fast? I mean is there a receive buffer of GPRS model ,and is there a limitation of the data of the M10 model transfer? if there is a limit size,how to solve it?
Maybe something wrong in the code.
Want your help!

GSM_FTP_ATC_V1.01.pdf (587 KB)

2error.jpg

I don’t understand what this piece of code is supposed to do:

    while(mFile.position()<filelength)
    {
        for(int i=0; i<3; i++)
        {
            mFile.read(filedata,1024);
            for(int j=0; j<sizeof(filedata); j++)
            {
                Serial.println(filedata[j],HEX);           // observe the image data through serial port
                mySerial.write(filedata[j]);
            }
        }
        delayMicroseconds(1000);
    }

What is the value of sizeof(filedata) and how does this relate to the number of bytes actually provided by read()?

PeterH:
I don’t understand what this piece of code is supposed to do:

    while(mFile.position()<filelength)

{
        for(int i=0; i<3; i++)
        {
            mFile.read(filedata,1024);
            for(int j=0; j<sizeof(filedata); j++)
            {
                Serial.println(filedata[j],HEX);           // observe the image data through serial port
                mySerial.write(filedata[j]);
            }
        }
        delayMicroseconds(1000);
    }




What is the value of sizeof(filedata) and how does this relate to the number of bytes actually provided by read()?

Hi, thanks for read it.
The function of the piece of the code you refered to is reading the jpg file data on the sdcard and transfering it to the FTP server.
“Filedata” is a 1024 bytes array buffer, read and send it, then again.
Using the code "sizeof(filedata) " is in consideration of the length of last jpg data segment maybe less than 1024.

Maybe read the jpg data and send it to gprs model so fast, I worried about the gprs model can not handle the data in time, so I add the code “delayMicroseconds(1000);”. But the data I got it is also false: the beginning about 10k byte data is right, the else is wrong.

I do not know where my mistake is! I need the help.

Let me restate the question:

What is the actual value of sizeof(filedata) and how does this relate to the number of bytes actually provided by read()?

Hint: the size is a constant, and the number of bytes by read() returned is not.

Hie,

I'm working on sending a text file from my SD card. For some reason I can not locate the file. I get a illegal file error message. How am I supposed to send data from my SD card. Do i first SD.open() the file then send or just give the file name with some special syntax.Thanks!

Maybe the baud rate of the software serial used to communicate with the m10 is too high.

Even though the m10 supports up to 115200 bps (on paper at least) you'll probably have to set a much lower rate. The software serial is not that fast. And even if the software serial is fast enough for the rate configured, the modem connection might not be fast or reliable enough.

I was trying to upload a 60 KB file (AT+QFTPPUT) and started at 57600 on the software serial for the m10. Only a third of the file would get uploaded to the server. Then I lowered the rate to 28800 and about two thirds of the file would get uploaded. Then I set the baud rate to 19200 and finally the whole file would get successfully uploaded. I retried several times at 19200 and the file would always get uploaded. 19200 seems to be the right rate for my scenario, but of course YMMV.

As for SD cards, the manufacturer states that they are only supported in the m33 model (see link below, section 2.2.8). The m10 cannot handle an SD card, you have to handle it yourself (eg using Arduino SD library) and then pass the data to the m10 serial.

http://www.quectel.com/UploadImage/Downlad/Quectel_GSM_FTP_AT_Commands_Manual_V1.4.pdf