Hi, I am struggling to send even a small txt file to my FTP server via GPRS.
The file is created but left empty.
The Console printout is as below:
Iniciando GPRS Transfer...
OK AT+SAPBR=3,1,'Contype','GPRS'
OK AT+SAPBR=3,1,"APN","claro.claro.com"
OK AT+SAPBR=3,1,"USER","claro"
OK AT+SAPBR=3,1,"PWD","claro"
OK AT+SAPBR=1,1 : OK
+SAPBR: 1,1,"100.67.75.26"
OK AT+SAPBR=2,1 : OK
OK AT+FTPCID=1 : OK
OK AT+FTPSERV= : OK
OK AT+FTPPORT=21 : OK
OK AT+FTPUN : OK
OK AT+FTPPW : OK
AT+FTPPW : OK
OK AT+FTPPUTNAME='1K.txt'
OK AT+FTPPUTPATH='/'
OK AT+FTPPUT=1
ERROR
+FTPPUT: 1,1,1360
AT+FTPPUT=2,10
Transfer cam_buff
OK AT+FTPPUT=2,0
SAPBR 1:DEACT
The sketch running on a TTGO Call is as below:
#define SerialAT Serial1
// TTGO T-Call pins
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON 23
#define MODEM_TX 27
#define MODEM_RX 26
void setup() {
Serial.begin(115200);
// Set modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(9600, SERIAL_8N1, MODEM_RX, MODEM_TX);
}
void loop() {
Serial.println("\n\nIniciando GPRS Transfer...");
sim_init();
gprs_configure_FTP();
delay(5000);
}
void sim_init(){
Serial1.print("AT\r\n");
delay(100);
Serial1.print("AT+CMGF=1\r\n");
delay(100);
Serial1.print("AT+SAPBR=0,1\r\n"); //checking
delay(2000);
}
void gprs_configure_FTP(){
char cam_buff[] = "###12345***";
sendATcommand("AT+SAPBR=3,1,\"Contype\",\"GPRS\"", "OK", 2000); Serial.println(" AT+SAPBR=3,1,'Contype','GPRS'");
sendATcommand("AT+SAPBR=3,1,\"APN\",\"claro.claro.com\"", "OK", 2000);Serial.println(" AT+SAPBR=3,1,\"APN\",\"claro.claro.com\"");
sendATcommand("AT+SAPBR=3,1,\"USER\",\"claro\"", "OK", 5000); Serial.println(" AT+SAPBR=3,1,\"USER\",\"claro\"");
sendATcommand("AT+SAPBR=3,1,\"PWD\",\"claro\"", "OK", 5000); Serial.println(" AT+SAPBR=3,1,\"PWD\",\"claro\"");
delay(5000);
sendATcommand("AT+SAPBR=1,1", "OK", 10000); Serial.println(" AT+SAPBR=1,1 : OK");
sendATcommand("AT+SAPBR=2,1", "OK", 2000); Serial.println(" AT+SAPBR=2,1 : OK");
sendATcommand("AT+FTPCID=1", "OK", 2000); Serial.println(" AT+FTPCID=1 : OK");
sendATcommand("AT+FTPSERV=ftp.ftpServer.com", "OK", 2000); Serial.println(" AT+FTPSERV= : OK");
sendATcommand("AT+FTPPORT=21", "OK", 2000); Serial.println(" AT+FTPPORT=21 : OK");
sendATcommand("AT+FTPUN=station@ftpServer.com", "OK", 2000); Serial.println(" AT+FTPUN : OK");
sendATcommand("AT+FTPPW=myPass", "OK", 2000); Serial.println("AT+FTPPW : OK"); Serial.println(" AT+FTPPW : OK");
sendATcommand("AT+FTPPUTNAME=\"1K.txt\"", "OK", 2000); Serial.println(" AT+FTPPUTNAME='1K.txt'");
sendATcommand("AT+FTPPUTPATH=\"/\"", "OK", 2000); Serial.println(" AT+FTPPUTPATH='/'");
sendATcommand("AT+FTPPUT=1", "OK", 30000); Serial.println(" AT+FTPPUT=1");
sendATcommand("AT+FTPPUT=2,100", "OK",30000); Serial.println(" AT+FTPPUT=2,10");
sendATcommand(cam_buff,"OK",30000); Serial.println(" Transfer cam_buff");
sendATcommand("AT+FTPPUT=2,0", "OK", 2000); Serial.println(" AT+FTPPUT=2,0");
sendATcommand("SAPBR 1:DEACT", "OK", 2000); Serial.println(" SAPBR 1:DEACT");
}
int8_t sendATcommand(char* ATcommand, char* expected_answer,unsigned int timeout){
uint8_t x = 0, answer = 0;
char response[100];
unsigned long previous;
memset(response, 0, 100); // Initialize the string
delay(100);
while (Serial1.available() > 0){
Serial1.read(); // Clean the input buffer
}
Serial1.println(ATcommand); // Send the AT command
x = 0;
previous = millis();
// this loop waits for the answer
do {
if (Serial1.available() != 0) {
// if there are data in the UART input buffer, reads it and checks for the asnwer
response[x] = Serial1.read();
Serial.print(response[x]);
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer) != NULL) {
answer = 1;
}
}
}
// Waits for the asnwer with time out
while ((answer == 0) && ((millis() - previous) < timeout));
return answer;
}
Help is welcome
Thanks
Paulo