Отправка FTP по GSM

Тема в разделе "Arduino & Shields", создана пользователем elfrom, 27 дек 2016.

  1. elfrom

    elfrom Нуб

    Добрый день,
    имеется SD карта и GSM SIM800c модем
    пытаюсь отправить файл 1.txt Ошибка
    +FTPPUT: 1,64
    Выходит ... подскажите в чем проблемка?

    Код (C++):
    #include <SPI.h>
    #include <SD.h>
    #include <SoftwareSerial.h>

    char* file_name1 = "1.txt"; // имя файла прикрепляемого
    char char_buffer;
    String string_buffer = "";
    int buffer_space = 1000;
    File dataFile;
    SoftwareSerial mySerial(6, 7);
    void setup() {
      Serial.begin(19200);
      mySerial.begin(19200);
      pinMode(10, OUTPUT);

      if (!SD.begin(10)) {
        Serial.println("Initialization failed!");
        return;
        while(true);
      }else {
        Serial.println("Initialization done.");
      }

      dataFile = SD.open(file_name1);
      if (dataFile) {
        Serial.println("Opening the file: " + String(file_name1) + " done.");
      }else {
        Serial.println("Error opening " + String(file_name1));
        while(true);
      }
     
      Serial.println("Starting...");
     
      Serial.println("Starting...");
      gprs_modem_function ();
      Serial.println("The end...");
    }


    void loop() {
      // put your main code here, to run repeatedly:
    }

    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.mts.ru\"", "OK", "ERROR", 1000);
          if (reply == 0){
            reply = sendATcommand("AT+SAPBR=3,1,\"USER\",\"mts\"", "OK", "ERROR", 1000);
            if (reply == 0){
              reply = sendATcommand("AT+SAPBR=3,1,\"PWD\",\"mts\"", "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+FTPMODE=1", "OK", "ERROR", 1000);  // Пассивный режим (1) Активный режим (0)
                     if (reply == 0){
                      reply = sendATcommand("AT+FTPSERV=\"118.24.21.103\"", "OK", "ERROR", 1000);  //сервер фтп, можно как айпи указать так и адрес типа ftp.tra-ta-ta.com
                      if (reply == 0){
                        reply = sendATcommand("AT+FTPPORT=21", "OK", "ERROR", 1000);
                        if (reply == 0){
                          reply = sendATcommand("AT+FTPUN=\"Ford\"", "OK", "ERROR", 1000);  // Логин Ford
                          if (reply == 0){
                            reply = sendATcommand("AT+FTPPW=\"Jastin\"", "OK", "ERROR", 1000); // Пароль Jastin
                            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));
                                  if (reply == 0){
                                    if (dataFile) {
                                      int i = 0;
                                      while (dataFile.available()>0) {
                                        char_buffer = dataFile.read();
                                        string_buffer.concat(char_buffer);
                                        i++;
                                        if (i == buffer_space) {
                                          sendATcommand("AT+FTPPUT=2," + String(buffer_space), "AT+FTPPUT=2,10", "ERROR", 1000);
                                          sendATcommand(string_buffer, "OK", "ERROR", 5000);
                                          string_buffer = "";
                                          i = 0;
                                        }
                                      }
                                      if (string_buffer != ""){
                                        sendATcommand("AT+FTPPUT=2," + String(i), "AT+FTPPUT=2,10", "ERROR", 1000);
                                        sendATcommand(string_buffer, "OK", "ERROR", 5000);
                                        sendATcommand("AT+FTPPUT=2,0", "OK", "ERROR", 1000);
                                      }
                                      dataFile.close();
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      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;
    }
     
  2. elfrom

    elfrom Нуб

    решилось, баланс увеличил на 100 рублей, заработало