carrascoacd / ArduinoSIM800L

Arduino HTTP & FTP client for SIM800L/SIM800 boards to perform GET and POST requests to a JSON API as well as FTP uploads.
159 stars 58 forks source link

Can it send large .txt files of like 10 MB? #46

Open bhupiister opened 3 years ago

bhupiister commented 3 years ago

Can it send large .txt files of like 10 MB? I will try this code on ESP32 board. Since its working on Arduino, it should work on esp32 too. I want to store sensor data all day and at night want to push this sensor data on server via FTP of HTTP post. Which is the recommended method ?

carrascoacd commented 3 years ago

I'd say that FTP is better in SIM800L: easier.

Try with small files instead, divide the 10mb file in small files and send them more often.

On Sun 23 Aug 2020, 6:54 p.m. bhupiister notifications@github.com wrote:

Can it send large .txt files of like 10 MB? I will try this code on ESP32 board. Since its working on Arduino, it should work on esp32 too. I want to store sensor data all day and at night want to push this sensor data on server via FTP of HTTP post. Which is the recommended method ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/carrascoacd/ArduinoSIM800L/issues/46, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBWFOBF2IRLIYVLCUOFEYDSCFCTBANCNFSM4QIYEMUQ .

bhupiister commented 3 years ago

I wanted some library that could do this division part. After putting this command AT+FTPPUT=1 OK +FTPPUT: 1,1,1360 Does this mean that maximum bytes that can be sent is 1360? How can we divide a file then?

bhupiister commented 3 years ago

Came across this code today for large files, will test it. See if you can get something from it to improve your library.

include

define csSD 5

bool debug = 1; bool roaming = false; char file_name = /"Filename"/; File dataFile; File dataFileCopy; const int Sim900PowerPin = 46; String apn_name = /"apn_name"/; String apn_username = ""; //not tested String apn_password = ""; //not tested String ftp = /"ftp adress/"; String ftp_user = /"ftp username"/; String ftp_password = /"ftp password*/";

void setup() { if (debug) {Serial.begin(19200);} Serial3.begin(19200); pinMode(csSD, OUTPUT);

//init SD Card byte answer = 0; int i = 0; while (i < 5 && answer == 0) { if (!SD.begin(csSD)) { if (debug) {Serial.println("SD Card initialization failed!");} i++; delay(500); } else { if (debug) {Serial.println("SD Card initialization done.");} answer = 1; } } if (answer == 0) {/Send SMS that init SD Card is failed/} //done init SD card

//check if file arivle else if(answer == 1) {answer = checkFile();} if (answer == 0) {/Send SMS that file is not avriable/}

//GPRS part else if(answer == 1) {answer = powerUp_Sim900();} if (answer == 0) {/Send SMS that powerUP is failed/} else if (answer == 1) {delay(20000); answer = initSim900();} //Delay to let startuo the SIM900 Module if (debug) {Serial.println("--- Answer initSim900: " + String(answer));} if (answer == 0) {/Send SMS that Sim900 init failed/} else if (answer == 1) {answer = initSim900FTP();} if (debug) {Serial.println("--- Answer initSim900FTP: " + String(answer));} if (answer == 0) {/Send SMS that Sim900FTP init failed/} else if (answer == 1) {answer = Sim900FTPSend();} if (debug) {Serial.println("--- Answer Sim900FTPSend: " + String(answer));} if (answer == 0) {/Send SMS that Sim900FTPSend failed/} }

void loop() {

}

byte initSim900() { byte answer = 0; int i = 0; while (i < 10 && answer == 0){ answer = sendATcommand("AT+CREG?","+CREG: 0,1", 1000); i++; delay(1000); } if (roaming and answer == 0) { while (i < 20 && answer == 0){ answer = sendATcommand("AT+CREG?","+CREG: 0,5", 1000); i++; delay(1000); } } if (answer == 1){answer = sendATcommand("AT+SAPBR=3,1,\"Contype\",\"GPRS\"","OK", 1000);} String com = "AT+SAPBR=3,1,\"APN\",\"" + apn_name + "\""; if (answer == 1){answer = sendATcommand(string2char(com), "OK", 1000);} /if (apn_username!= "") { com = "AT+SAPBR=3,1,\"USER\",\"" + apn_username + "\""; if (answer == 1){answer = sendATcommand(string2char(com), "OK", 1000);}; if (apn_password != "") { com = "AT+SAPBR=3,1,\"PWD\",\"" + apn_password + "\""; if (answer == 1){answer = sendATcommand(string2char(com), "OK", 1000);} } }/ if (answer == 1){ answer = 0; i = 0; while (i < 3 && answer == 0){ answer = sendATcommand("AT+SAPBR=1,1", "OK", 10000); if (answer == 0){sendATcommand("AT+SAPBR=0,1", "OK", 10000);} i++; } } if (answer == 1){answer = sendATcommand("AT+SAPBR=2,1", "OK", 1000);} return answer; }

byte initSim900FTP() { byte answer = 0; answer = sendATcommand("AT+FTPCID=1", "OK", 1000); String com = "AT+FTPSERV=\"" + ftp + "\""; if (answer == 1){answer = sendATcommand(string2char(com), "OK", 1000);} if (answer == 1){answer = sendATcommand("AT+FTPPORT=21", "OK", 1000);} com = "AT+FTPUN=\"" + ftp_user + "\""; if (answer == 1){answer = sendATcommand(string2char(com), "OK", 1000);} com = "AT+FTPPW=\"" + ftp_password + "\""; if (answer == 1){answer = sendATcommand(string2char(com), "OK", 1000);} com = "AT+FTPPUTNAME=\"" + String(file_name) + "\""; if (answer == 1){answer = sendATcommand(string2char(com), "OK", 1000);} if (answer == 1){answer = sendATcommand("AT+FTPPUTPATH=\"/\"", "OK", 1000);} return answer; }

byte Sim900FTPSend (){ byte answer = 0; if (answer = sendATcommand("AT+FTPPUT=1", "+FTPPUT:1,1,", 60000) == 1) { int data_size = 0; while(Serial3.available()==0); char aux = Serial3.read(); do{ data_size *= 10; data_size += (aux-0x30); while(Serial3.available()==0); aux = Serial3.read();
} while(aux != 0x0D); dataFile = SD.open(file_name); 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 (dataFile) {
  int archivosize = dataFile.size();
  while(dataFile.available() and answer == 1){
    while(archivosize >= data_size){
      if (answer = sendATcommand(XxcomA,XxcomB,3000) == 1) {
        for(int d = 0; d < data_size; d++){
          Serial3.write(dataFile.read());
          archivosize -= 1;
        }
      }
      else {answer = 0;}
    }
    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,3000) == 1) {
      for(int t = 0; t < archivosize; t++){
        Serial3.write(dataFile.read());
      }
    }
  }
  // close the file:
  dataFile.close();
}
delay(500);
if (sendATcommand("AT+FTPPUT=2,0", "+FTPPUT:1,0", 30000)==1){
  if (debug) {Serial.println("File " + String(file_name) + " uploaded..." );}
}         

} else {answer = 0;} return answer; }

unsigned char sendATcommand(char ATcommand, char expected_answer1, unsigned int timeout) { unsigned char x = 0; unsigned char answer = 0; char response[100]; unsigned long previous; memset(response, '\0', 100); delay(100); while( Serial3.available() > 0) Serial3.read(); Serial3.println(ATcommand); x = 0; previous = millis(); do{ if(Serial3.available() != 0){
response[x] = Serial3.read(); x++; if (strstr(response, expected_answer1) != NULL) { answer = 1; } } } while((answer == 0) && ((millis() - previous) < timeout)); if (debug) {Serial.println(response);} return answer; }

byte powerUp_Sim900() { byte answer = 0; int i = 0; powerSim900(); while (i < 2 && answer == 0){ answer = sendATcommand("AT+CREG?","+CREG:", 1000); i++; delay(500); } if (answer == 0) {powerSim900();} i = 0; while (i < 2 && answer == 0){ answer = sendATcommand("AT+CREG?","+CREG:", 1000); i++; delay(500); } return answer; //send 1 if power up }

byte powerDown_Sim900() { byte answer = 0; int i = 0; powerSim900(); while (i < 2 && answer == 0){ answer = sendATcommand("AT+CREG?","+CREG:", 1000); i++; delay(500); } if (answer == 1) {powerSim900();} i = 0; while (i < 2 && answer == 1){ answer = sendATcommand("AT+CREG?","+CREG:", 1000); i++; delay(500); } return answer; //send 0 if power up }

void powerSim900() { pinMode(Sim900PowerPin, OUTPUT); digitalWrite(Sim900PowerPin,LOW); delay(1000); digitalWrite(Sim900PowerPin,HIGH); delay(2000); digitalWrite(Sim900PowerPin,LOW); delay(5000); }

char string2char(String command){ if(command.length() != 0){ char p = const_cast<char*>(command.c_str()); return p; } }

byte checkFile() { byte answer = 0; if(SD.exists(file_name)) {answer = 1;} return answer; }

carrascoacd commented 3 years ago

It means that the max chunk size is 1360 bytes per request.

Try writing small files (some Kb) more often and upload them. Do not try to divide the 10mb one.

On Sun 23 Aug 2020, 7:48 p.m. bhupiister notifications@github.com wrote:

I wanted some library that could do this division part. After putting this command AT+FTPPUT=1 OK +FTPPUT: 1,1,1360 Does this mean that maximum bytes that can be sent is 1360? How can we divide a file then?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/carrascoacd/ArduinoSIM800L/issues/46#issuecomment-678803830, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBWFOHKRXYJUMFJ7XD4U33SCFI7LANCNFSM4QIYEMUQ .

basurilla82 commented 1 year ago

Hello, have you solve this problem?. I want to send a big picture file by ftp with sim800l and esp32 (not wifi). Please, can you write your final code source?. Thanks.