HI,
I am using an arduino uno R3 and a GSM/GPRS shield (SIM900) to download files from an FTP server using the sim900 AT commands. The code and the responses to the code from the sim900 are given below. Everything seems to work except for actually getting the data from the server which is when i get the timeout error. The main problem is that i cant "see" the server responses to see what is causing the timeout error. The timeout error is indicated by +FTPGET=1,64 (64 = timeout) should be +FTPGET=1,1 every thing after the time out obviously fails.
Can anybody see any problems with how i am doing this and maybe suggest a better way (TCP/IP??).
Any help is much appreciated.
Cheers.
#include <SoftwareSerial.h>
SoftwareSerial sim900(7, 8);
int x;
char data[1024];
void setup(){
Serial.begin(9600); // UART baud rate
sim900.begin(19200);
Serial.println("Starting FTP Download...");
for (int i=0;i< 5;i++){
delay(2000);
}
//Serial.println("AT+CGSOCKCONT=1,\"IP\",\"myapn\"");
//Serial.flush();
//response();
}
void loop() {
sim900.println("AT"); //check AT
sim900Reply();
sim900.println("AT+CSQ"); //check signal strength
sim900Reply();
sim900.println("AT+CGATT?");
sim900Reply();
sim900.println("AT+CSTT");
sim900Reply();
/*sim900.println("AT+CIICR");
//Serial.flush();
sim900Reply();
sim900.println("AT+CIFSR");
//Serial.flush();
sim900Reply();*/
sim900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
sim900Reply();
sim900.println("AT+SAPBR=3,1,\"APN\",\"internet\"");
sim900Reply();
sim900.println("AT+SAPBR=1,1");
sim900Reply();
sim900.println("AT+FTPCID=1");
sim900Reply();
sim900.println("AT+FTPMODE=1");
sim900Reply();
sim900.println("AT+FTPTYPE=\"A\"");
sim900Reply();
sim900.println("AT+FTPSERV=\"ftp.xxxx.xx.xx\""); //write your FTP server domain
sim900Reply();
sim900.println("AT+FTPUN=\"user\"");
sim900Reply();
sim900.println("AT+FTPPW=\"pass\"");
sim900Reply();
sim900.println("AT+FTPGETNAME=\"test.log\"");
sim900Reply();
sim900.println("AT+FTPGETPATH=\"/file/path/\""); //write the correct directory path.
sim900Reply();
sim900.println("AT+FTPGET=1"); //starts FTP session
sim900Reply();
sim900Reply2();
sim900.println("AT+FTPGET=2,1024"); // gets 1024 bytes of data
sim900Reply();
}
void sim900Reply() {
x=0;
do{
//Serial.println("in here"); //testing
while(sim900.available()==0);
data[x]=sim900.read();
Serial.print(data[x]);
x++;
} while(!(data[x-1]=='K'&&data[x-2]=='O'));
}
void sim900Reply2() {
x=0;
do{
while(sim900.available()==0);
data[x]=sim900.read();
Serial.print(data[x]);
x++;
} while(!(data[x]=='+'));
do{
while(sim900.available()==0);
data[x]=sim900.read();
Serial.print(data[x]);
x++;
} while(!(data[x]=='\n')||(data[x]=='\r'));
}
SIM900 reponses;
Starting FTP Download...
AT
OK
AT+CSQ
+CSQ: 23,0
OK
AT+CGATT?
+CGATT: 1
OK
AT+CSTT
OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
OK
AT+SAPBR=3,1,"APN","internet"
OK
AT+SAPBR=1,1
OK
AT+FTPCID=1
OK
AT+FTPMODE=1
OK
AT+FTPTYPE="A"
OK
AT+FTPSERV="ftp.xxxx.xx.xx"
OK
AT+FTPUN="user"
OK
AT+FTPPW="pass"
OK
AT+FTPGETNAME="test.log"
OK
AT+FTPGETPATH="/file/path/"
OK
AT+FTPGET=1
OK
+FTPGET:1,64
AT+FTPGET=2,1024
+CME ERROR: operation not allowed