Please help me I am trying to upload an image to ftp. I used the codes on this link How to upload an image (200KB) from SDcard to FTP server using sim800/sim900 - Networking, Protocols, and Devices - Arduino Forum but it is stuck on a loop because it is not getting the right value.
here is my full code
byte gprs_modem_function () {
byte reply = 1;
int i = 0;
while (i < 10 && reply == 1) { //Try 10 times...
reply = sendATcommand("AT+CREG?", "+CREG: 0,1", "ERROR", 1000);
i++;
delay(1000);
}
if (reply == 0) {
reply = sendATcommand("AT+SAPBR=3,1,\"Contype\",\"GPRS\"", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+SAPBR=3,1,\"APN\",\"internet\"", "OK", "ERROR", 1000);
if (reply == 0) {
//reply = sendATcommand("AT+SAPBR=3,1,\"USER\",\"entelpcs\"", "OK", "ERROR", 1000);
if (reply == 0) {
//reply = sendATcommand("AT+SAPBR=3,1,\"PWD\",\"entelpcs\"", "OK", "ERROR", 1000);
if (reply == 0) {
reply = 2;
i = 0;
while (i < 3 && reply == 2) { //Try 3 times...
reply = sendATcommand("AT+SAPBR=1,1", "OK", "ERROR", 10000);
if (reply == 2) {
sendATcommand("AT+SAPBR=0,1", "OK", "ERROR", 10000);
}
i++;
}
if (reply == 0) {
reply = sendATcommand("AT+SAPBR=2,1", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+FTPCID=1", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+FTPSERV=\"files.000webhost.com\"", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+FTPPORT=21", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+FTPUN=\"security\"", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+FTPPW=\"123456\"", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+FTPPUTNAME=\"" + String(file_name1) + "\"", "OK", "ERROR", 1000);
if (reply == 0) {
reply = sendATcommand("AT+FTPPUTPATH=\"/\"", "OK", "ERROR", 1000);
if (reply == 0) {
unsigned int ptime = millis();
reply = sendATcommand("AT+FTPPUT=1", "+FTPPUT: 1,1", "+FTPPUT: 1,6", 60000);
Serial.println("Time: " + String(millis() - ptime));
}
int data_size = 0;
while(mySerial.available());
char aux = mySerial.read();
do {
data_size *= 10;
data_size += (aux - 0x30);
while(mySerial.available());
aux = mySerial.read();
Serial.println(aux);
} while (aux != 0x0D);
Serial.println("wewwewew");
File1 = SD.open(file_name1);
String XcomA = "";
String XcomB = "";
XcomA.concat("AT+FTPPUT=2,");
XcomA.concat(data_size);
XcomA.concat("\"");
XcomB.concat("+FTPPUT:2,");
XcomB.concat(data_size);
XcomB.concat("\"");
char XxcomA[XcomA.length()];
char XxcomB[XcomB.length()];
XcomA.toCharArray(XxcomA, XcomA.length());
XcomB.toCharArray(XxcomB, XcomB.length());
if (File1) {
int archivosize = File1.size();
while (File1.available()) {
while (archivosize >= data_size) {
if (sendATcommand(XxcomA, XxcomB, "OK", 3000) == 1) {
for (int d = 0; d < data_size; d++) {
mySerial.write(File1.read());
archivosize -= 1;
}
}
}
String ScomA = "";
String ScomB = "";
ScomA.concat("AT+FTPPUT=2,");
ScomA.concat(archivosize);
ScomA.concat("\"");
ScomB.concat("+FTPPUT:2,");
ScomB.concat(archivosize);
ScomB.concat("\"");
char CcomA[ScomA.length()];
char CcomB[ScomB.length()];
ScomA.toCharArray(CcomA, ScomA.length());
ScomB.toCharArray(CcomB, ScomB.length());
if (sendATcommand(CcomA, CcomB, "OK", 3000) == 1) {
for (int t = 0; t < archivosize; t++) {
mySerial.write(File1.read());
}
}
}
// close the file:
File1.close();
delay(500);
if (sendATcommand("AT+FTPPUT=2,0", "+FTPPUT:1,0", "OK", 30000) == 1) {
Serial.println("File " + String(file_name1) + " uploaded..." );
}
else
Serial.println("Error openning the FTP session");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return reply;
}
byte sendATcommand(String ATcommand, String answer1, String answer2, unsigned int timeout) {
byte reply = 1;
String content = "";
char character;
//Clean the modem input buffer
while (mySerial.available() > 0) mySerial.read();
//Send the atcommand to the modem
mySerial.println(ATcommand);
delay(100);
unsigned int timeprevious = millis();
while ((reply == 1) && ((millis() - timeprevious) < timeout)) {
while (mySerial.available() > 0) {
character = mySerial.read();
content.concat(character);
Serial.print(character);
delay(10);
}
//Stop reading conditions
if (content.indexOf(answer1) != -1) {
reply = 0;
} else if (content.indexOf(answer2) != -1) {
reply = 2;
} else {
//Nothing to do...
}
}
return reply;
}
it is stuck on this loop
do {
data_size *= 10;
data_size += (aux - 0x30);
while(mySerial.available());
aux = mySerial.read();
Serial.println(aux);
} while (aux != 0x0D);
when I print aux I only get "?" values