I've been unable to FTP anything using an Arduino and SIM800L. I have reduced the code as far as possible:
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
String moduleAnswer = "";
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
SoftwareATCommand("AT"); //Once the handshake test is successful, it will back to OK
SoftwareATCommand("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
SoftwareATCommand("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
SoftwareATCommand("AT+CREG?"); //Check whether it has registered in the network
//APN and GRPS Setup
SoftwareATCommand("AT+SAPBR=0,1"); //Close GPRS before connecting
SoftwareATCommand("AT+SAPBR=3,1,\"Contype\",\"GPRS\""); //Configure bearer profile
SoftwareATCommand("AT+SAPBR=1,1"); //Connect to GPRS
//FTP Connection
SoftwareATCommand("AT+FTPCID=1");
SoftwareATCommand("AT+FTPSERV=127.189.249.205"); //Not real IP
SoftwareATCommand("AT+FTPPORT=21");
SoftwareATCommand("AT+FTPUN=user");
SoftwareATCommand("AT+FTPPW=pass");
//FTP Upload
uploadFTP();
}
void loop()
{
}
void uploadFTP()
{
SoftwareATCommand("AT+FTPPUTNAME=\"test.txt\""); //Filename
SoftwareATCommand("AT+FTPPUTPATH=/home/arduino/SolarDataLogger/"); //Path
SoftwareATCommand("AT+FTPPUT=1"); //Start FTP
delay(10000);
SoftwareATCommand("AT+FTPPUT=2,100"); //Send 100 bytes of data
delay(10000);
SoftwareATCommand("Hello12345"); //Send Data
SoftwareATCommand("AT+FTPPUT=2,0"); //Close FTP
}
String SoftwareATCommand(String strAT)
{
String strNotice = "Sending: " + strAT;
Serial.println(strNotice);
mySerial.println(strAT);
delay(500);
moduleAnswer = "No Response";
while(mySerial.available())
{
moduleAnswer = mySerial.readString();
char* buf = (char*) malloc(sizeof(char)*moduleAnswer.length()+1);
moduleAnswer.toCharArray(buf, moduleAnswer.length()+1);
Serial.write(buf);//Forward what Software Serial received to Serial Port
- Module answer sent to screen
free(buf);
}
return moduleAnswer;
}
The serial output where the trouble is:
I've tried waiting longer for the +FTPPUT: 1,1,1360
response or sending something twice, but nothing seems to work. The file gets created but no other data is ever sent.
3 Answers 3
The line +FTPPUT: 1,65 indicates a server error.
https://www.elecrow.com/wiki/images/2/20/SIM800_Series_AT_Command_Manual_V1.09.pdf - page 275.
Please check a sequence of commands, maybe something is missing?
I use the following sequence:
"AT+CREG?"
"AT+SAPBR=3,1,\"Contype\",\"GPRS\""
"AT+SAPBR=3,1,\"APN\",\"NAME OF YOUR PROVIDER \""
"AT+SAPBR=1,1"
"AT+SAPBR=2,1"
"AT+FTPCID=1"
"AT+FTPSERV=\"SERVER ADDRESS\""
"AT+FTPPORT=21"
"AT+FTPTYPE=\"I\""
"AT+FTPUN=\"USERNAME\""
"AT+FTPPW=\"PASSWORD\""
"AT+FTPPUTNAME=\"" + NAME OF FILE + "\""
"AT+FTPPUT=1"
"AT+FTPPUT=2," + STRING OF BUFFER SPACE ( Get from response of FTPPUT=1 )
"AT+FTPPUT=2,0"
Look in the manual for the commands above.
-
Thanks for the input. I posted this after moving to a Pi instead for anybody else that might run into the same issue and I think your input will be useful to someone.Jak– Jak10/09/2019 06:26:40Commented Oct 9, 2019 at 6:26
what I observed in your code-I think you did not follow the proper sequence of connecting the GPRS context mentioned in the sim800l datasheet.
Please follow the section 3.1. bearer configuration. I also attached the screenshot herewith. So you missed setting the Access Point Name(APN). After you query the GPRS context(last step in the image), if you get the proper IP address, then you are sure to send the data over FTP. Please follow the FTP sequence mentioned in the datasheet.
enter image description here
Everything is okay for now +FTPPUT: 1,1,1360
as the module (in accordance with a network) allows you to send 1360 bytes in a row.
Then you asked the module to send 100 bytes: AT+FTPPUT=2,100
and your module acknowledges it: +FTPPUT: 2,100
.
After that you have to send those 100 bytes. But you sent only Hello12345
and AT+FTPPUT=2,0
. You didn't provide all the data you asked for. The string AT+FTPPUT=2,0
is now used as the data to be send and not interpreted as a command to stop the data transfer. So the module waits for the rest of data for a while and finally aborts the operation. You should have asked for 10 bytes in your test. Then your data would have been acknowledged by OK
and another +FTPPUT: 1,1,1360
. Remember, no CR LF at the end this time, only data to be stored in a file.
BTW, you can even send a little more data than you asked for. The module omits them without throwing an error.